PozoApp-retail-designChanges/src/Features/Kiosk/check.js

381 lines
12 KiB
JavaScript

import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';
import {
axiosRetailInstanceData,
axiosCommonInstanceData,
} from '../../AuthenicationToken/AuthenticationToken';
import { getSession } from '../../../Services/Others';
import { getSelfBooking } from '../../TableBooking/TableBooking';
const Paymentdevice_POST_URL = import.meta.env.ENV_PAYMENT_DEVICE_URL;
const Paymentdevice_GET_URL = import.meta.env.ENV_PAYMENT_STATUS_GET_URL;
const apiCommonUrl = import.meta.env.ENV_API_URL_COMMON;
export const getProductCategories = createAsyncThunk(
'KioskBookingData/getLayoutCategories',
async ({ CompId, BranchId, AppId }) => {
if (
CompId != null &&
CompId != undefined &&
BranchId != null &&
BranchId != undefined &&
AppId != null &&
AppId != undefined
) {
return await axiosRetailInstanceData.get(
`/productCat?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}`
);
}
}
);
export const getProductCardListKiosk = createAsyncThunk(
'KioskBookingData/getProductCardListKiosk',
async ({ CompId, BranchId, AppId, ProdCat }) => {
if (
CompId != null &&
CompId != undefined &&
BranchId != null &&
BranchId != undefined &&
AppId != null &&
AppId != undefined &&
ProdCat != null &&
ProdCat != undefined
) {
return await axiosRetailInstanceData.get(
`/ProductCardList?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}&prodCat=${ProdCat}`
);
}
}
);
export const PostKioskBookingData = createAsyncThunk(
'BookingData/PostKioskBookingdata',
async (postData) => {
return await axiosRetailInstanceData.post(`/KioskBooking`, postData);
}
);
export const PutKioskBookingData = createAsyncThunk(
'BookingData/PutKioskBookingdata',
async (putData) => {
return await axiosRetailInstanceData.put(`/KioskBooking`, putData);
}
);
export const PutBookingPaymentStatusChange = createAsyncThunk(
'BookingData/PutBookingPaymentStatusChange',
async (putData) => {
return await axiosRetailInstanceData.put(`/BookingPaymentStatus`, putData);
}
);
// http://192.168.1.37:8001/ProductCardList?request.compId=1&request.branchId=1&request.appId=2&request.prodCat=224
export const getCompanyData = createAsyncThunk(
'appAccess/getCompanyData',
async ({ CompId }) => {
if (CompId != null && CompId != undefined) {
return await axios.get(`${apiCommonUrl}/company?CompId=${CompId}`);
}
}
);
export const getPaymentGatewayConfig = createAsyncThunk(
'getPaymentGatewayConfig',
async ({ CompId, AppId, BranchId }) => {
if (
CompId != null &&
CompId != undefined &&
BranchId != null &&
BranchId != undefined &&
AppId != null &&
AppId != undefined
) {
return await axiosCommonInstanceData.get(
`/PaymentGatewayConfig?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}`
);
}
}
);
export const getPaymentGatewayDetails = createAsyncThunk(
'getPaymentGatewayDetails',
async ({ CompId, AppId, BranchId, DetailType }) => {
if (
CompId != null &&
CompId != undefined &&
BranchId != null &&
BranchId != undefined &&
AppId != null &&
AppId != undefined
) {
return await axiosRetailInstanceData.get(
`/upi?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}&detailType=${DetailType}`
);
}
}
);
export const getAllApplications = createAsyncThunk(
'application/getApplicationData',
async ({ AppId }) => {
if (AppId != null && AppId != undefined) {
return axios.get(`${apiCommonUrl}/application?AppId=${AppId}`);
}
}
);
export const getDeviceAccess = createAsyncThunk(
'agetDeviceAccess',
async ({ DeviceAddress }) => {
if (DeviceAddress != null && DeviceAddress != undefined) {
return axiosCommonInstanceData.get(
`/DeviceInfo?DeviceAddress=${DeviceAddress}`
);
}
}
);
export const getPaymentOptionsData = createAsyncThunk(
'getPaymentOptionsData',
({ AppId, CompId, BranchId }) => {
const UserType = getSession('UserType');
if (
CompId != null &&
CompId != undefined &&
BranchId != null &&
BranchId != undefined &&
AppId != null &&
AppId != undefined &&
UserType !== 'Super Admin' &&
UserType !== 'Super Admin User'
) {
return axiosRetailInstanceData.get(
`/paymentOptions?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}`
);
}
}
);
export const getPaymentDeviceAccessData = createAsyncThunk(
'getPaymentDeviceAccessData',
({ AppId, CompId, BranchId, UserId }) => {
if (
CompId != null &&
CompId != undefined &&
BranchId != null &&
BranchId != undefined &&
AppId != null &&
AppId != undefined &&
UserId != null &&
UserId != undefined
) {
return axiosRetailInstanceData.get(
`/PaymentDeviceAccess?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}&UserId=${UserId}`
);
}
}
);
export const getPaymentGatewayAccessData = createAsyncThunk(
'getPaymentGatewayAccessData',
({ AppId, CompId, BranchId, ActiveStatus }) => {
if (
CompId != null &&
CompId != undefined &&
BranchId != null &&
BranchId != undefined &&
AppId != null &&
AppId != undefined
) {
return axiosCommonInstanceData.get(
`/PaymentGatewayConfig?CompId=${CompId}&BranchId=${BranchId}&AppId=${AppId}&ActiveStatus=${ActiveStatus}`
);
}
}
);
export const postPaymentDevice = createAsyncThunk(
'postPaymentDevice',
async (data, { rejectWithValue }) => {
try {
const response = await axios.post(`${Paymentdevice_POST_URL}`, data, {
headers: {
'Content-Type': 'application/json', // Set the Content-Type header
// Add any other headers here if needed
},
});
console.log('Response Data:', response?.data); // Log the response data
return response?.data;
} catch (error) {
console.error('Request Error:', error);
return rejectWithValue(error.response?.data || error.message);
}
}
);
export const getPaymentDeviceResponse = createAsyncThunk(
'getPaymentDeviceResponse',
async (data, { rejectWithValue }) => {
try {
const response = await axios.post(`${Paymentdevice_GET_URL}`, data, {
headers: {
'Content-Type': 'application/json', // Set the Content-Type header
},
});
console.log('Response Data:', response?.data); // Log the response data
return response?.data;
} catch (error) {
console.error('Request Error:', error);
return rejectWithValue(error.response?.data || error.message);
}
}
);
const initialState = {
BookingType: 'TakeAway',
ProdCat: null,
CategorieData: [],
ProductCardList: [],
KioskOrderDetails: [],
OrderbtnClicked: false,
OrderId: null,
SalesId: null,
KioskBookingTypeBoth: false,
PaymentgatewayRedirect: false,
PGFailedTransId: null,
PGFailedAmt: null,
MergeData: [], // Add merge data to global state
};
const KioskBookingData = createSlice({
name: 'KioskBookingData',
initialState,
reducers: {
changeProductCategorie: (state, action) => {
state.ProdCat = action?.payload;
},
changeBookingType: (state, action) => {
state.BookingType = action?.payload;
},
changeCategorieData: (state, action) => {
state.CategorieData = action?.payload;
},
changeProductCardListData: (state, action) => {
state.ProductCardList = action?.payload;
},
changePaymentgatewayRedirect: (state, action) => {
state.PaymentgatewayRedirect = action?.payload;
},
changeAllGlbStatustData: (state, action) => {
(state.BookingType = 'TakeAway'),
(state.KioskOrderDetails = []),
(state.OrderbtnClicked = false),
(state.OrderId = null),
(state.ProdCat = null),
state.CategorieData;
// cart clear
},
changeKioskOrderDetails: (state, action) => {
state.KioskOrderDetails = action?.payload;
const result =
action?.payload?.some(
(product) => product.BookingTypeName === 'TakeAway'
) &&
action?.payload?.some(
(product) => product.BookingTypeName === 'Dine In'
);
state.KioskBookingTypeBoth = result ? true : false;
},
changeOrderbtnClicked: (state, action) => {
state.OrderbtnClicked = action?.payload;
},
changeOrderId: (state, action) => {
state.OrderId = action?.payload;
},
changeSalesId: (state, action) => {
state.SalesId = action?.payload;
},
changePGFailedTransId: (state, action) => {
state.PGFailedTransId = action?.payload;
},
changePGFailedAmt: (state, action) => {
state.PGFailedAmt = action?.payload;
},
changeMergeData: (state, action) => {
state.MergeData = action?.payload;
},
},
extraReducers: (builder) => {
builder.addCase(getProductCategories.fulfilled, (state, action) => {
if (action?.payload?.data?.statusCode == 1) {
state.CategorieData = action?.payload?.data?.data;
state.ProdCat = action?.payload?.data?.data[0].ProdCat;
} else {
state.CategorieData = action?.payload?.data?.data;
state.ProdCat = null;
}
}),
builder.addCase(getProductCardListKiosk.fulfilled, (state, action) => {
if (action?.payload?.data?.statusCode == 1) {
state.ProductCardList = action?.payload?.data?.data;
} else {
state.ProductCardList = [];
}
});
builder.addCase(getSelfBooking.fulfilled, (state, action) => {
if (action?.payload?.data?.statusCode == 1) {
state.KioskOrderDetails =
action?.payload?.data?.data?.[0]?.productDetails?.map((item) => ({
...item,
disabled: true,
}));
state.OrderId = action?.payload?.data?.data?.[0]?.OrderId;
state.SalesId = action?.payload?.data?.data?.[0]?.SalesId;
} else {
state.KioskOrderDetails = [];
}
});
},
});
export const {
changeProductCategorie,
changeBookingType,
changeCategorieData,
changeProductCardListData,
changeAllGlbStatustData,
changeKioskOrderDetails,
changeOrderbtnClicked,
changeOrderId,
changePaymentgatewayRedirect,
changePGFailedTransId,
changePGFailedAmt,
changeSalesId,
changeMergeData,
} = KioskBookingData.actions;
export const GlobalBookingTypeKiosk = (state) =>
state?.KioskBookingData?.BookingType;
export const GlobalProductCategorieKiosk = (state) =>
state?.KioskBookingData?.ProdCat;
export const GlobalCategorieDataKiosk = (state) =>
state?.KioskBookingData?.CategorieData;
export const GlobalProductCardListKiosk = (state) =>
state?.KioskBookingData?.ProductCardList;
export const GlobalKioskOrderDetails = (state) =>
state?.KioskBookingData?.KioskOrderDetails;
export const GlobalOrderbtnClicked = (state) =>
state?.KioskBookingData?.OrderbtnClicked;
export const GlobalOrderId = (state) => state?.KioskBookingData?.OrderId;
export const GlobalSalesId = (state) => state?.KioskBookingData?.SalesId;
export const GlobalKioskBookingTypeBoth = (state) =>
state?.KioskBookingData?.KioskBookingTypeBoth;
export const GlobalPaymentgatewayRedirect = (state) =>
state?.KioskBookingData?.PaymentgatewayRedirect;
export const GlobalPGFailedTransId = (state) =>
state?.KioskBookingData?.PGFailedTransId;
export const GlobalPGFailedAmt = (state) =>
state?.KioskBookingData?.PGFailedAmt;
export const GlobalMergeData = (state) => state?.KioskBookingData?.MergeData;
export default KioskBookingData.reducer;