import React, { useEffect, useRef, useState, useCallback, forwardRef, useImperativeHandle } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import WebFont from 'webfontloader';
import { SwatchesPicker } from 'react-color';
import { DefaultModal } from '../../../../Components/Modal/DefaultModal';
import { RadioGrpButton } from '../../../../Components/Forms/RadioGroup.jsx';
import {
CloseOutlined,
ArrowRightOutlined,
} from '@ant-design/icons';
import { BiSkipPrevious } from 'react-icons/bi';
import { BiSkipNext } from 'react-icons/bi';
import { Modal, Form } from 'antd';
import { Checkbox, Row } from 'antd';
import { DropDowns } from '../../../../Components/Forms/DropDown';
import {
selectedFontId,
selectedColorId,
getCatFonts,
getSubCatFonts,
getCardFonts,
getTableFonts,
postColorData,
GlobalCatData,
GlobalSubcatData,
GlobalCardData,
GlobalTableData,
postCatFontData,
postSubcatFontData,
postCardFontData,
postTableFontData,
getLayout,
getNavbar,
getCategory,
getCard,
getSubCategory,
getBillingTable,
changeSelectedLayout,
changeSelectedNavbar,
changeSelectedCategory,
changeSelectedSubCategory,
changeSelectedNavbarCheckedItems,
changeSelectedCategoryCheckedItems,
changeSelectedSubCategoryCheckedItems,
changeSelectedCardCheckedItems,
changeSelectedCard,
changeSelectedBillingTable,
changeSelectedBillTableCheckedItems,
postSelectionComponentData,
putSelectionComponentData,
changePreviewComponents,
getCombo1Navbar,
getCombo2Navbar,
getTemplateData,
getTemplate,
getColorsDataCat,
getColorsDataSubcat,
getColorsDataCard,
getColorsDataBilltable,
getColorsCat,
getColorsSubcat,
getColorsCard,
getLayoutOverallBackgroundColors,
GlobalLayoutOverallbackgroundlist,
GlobalSubcategoryOverallColorsList,
GlobalCategoryOverallColorsList,
GlobalcardOverallColorsList,
GlobalBillingOverallColorsList,
getCategoryOverallBackgroundColors,
getSubcategoryOverallBackgroundColors,
getCardOverallBackgroundColors,
getBillingOverallBackgroundColors,
getColorsBilltable,
SelectedGlobalCardFont,
SelectedGlobalBillingFont,
SelectedGlobalCatgFont,
SelectedGlobalSubCatgFont,
changeSelectedCardColorDetail,
changeSelectedBillingColorDetail,
changeSelectedCatgColorDetail,
changeSelectedSubCatgColorDetail,
changeSelectedLayoutColorDetail,
changeSelectedBillingFont,
changeSelectedCardFont,
changeSelectedCatgFont,
changeSelectedSubCatgFont,
SelectedGlobalCardColorDetail,
SelectedGlobalBillingColorDetail,
SelectedGlobalCatgColorDetail,
SelectedGlobalSubCatgColorDetail,
getThemes,
changeThemeCreation,
getThemeCreation,
getOthersTemplate,
GlobalDefaultTheme,
GlobalSelectedTheme,
changeSelectedTheme,
changeOthersTheme,
GlobalActiveTheme,
changeActiveTheme,
changeScanTemplate,
} from '../../../../Features/ThemeChange/ThemeChange';
import { InputField } from '../../../../Components/Forms/InputField.jsx';
import { Messages } from '../../../../Components/Notifications/Messages';
import Buttons from '../../../../Components/Forms/Buttons';
import { getSession, validateSafeInput } from '../../../../Services/Others';
import '../../../../Styles/BookingScreen/Components/SelectionComponent/SelectionComponent.scss';
import {
changeBreadCrumb,
getEmpAccess,
} from '../../../../Features/AppPage/CenterPage';
import { getPreferenceData } from '../../../../Features/BookingScreen/BookingData/BookingData.js';
import { useAuth } from '../../../../AuthContext.jsx';
import { HiOutlineSquares2X2, HiSquaresPlus } from 'react-icons/hi2';
import { ApplicationPreferences, getCommonAppPreference } from '../../../../Features/BrachLogin/BranchLogin.js';
import { TbLayoutNavbar } from 'react-icons/tb';
import { HiMenuAlt1 } from 'react-icons/hi';
import { IoMdAdd } from "react-icons/io";
import { LuCreditCard } from "react-icons/lu";
import { IoReceiptOutline } from "react-icons/io5";
const subDirectory = import.meta.env.BASE_URL;
const SelectionComponent = forwardRef((props, ref) => {
const { SadminuserAccess } = useAuth();
console.log(SadminuserAccess, 'SadminuserAccess');
let SAAccessCommonMaster = SadminuserAccess?.find(
(e) => e?.MenuName === 'Sales Screen'
);
const dispatch = useDispatch();
const formRef = useRef(null);
const [form] = Form.useForm();
const [Catform] = Form.useForm();
const [Subform] = Form.useForm();
const [Cardform] = Form.useForm();
const [Tableform] = Form.useForm();
const [isFormValid, setIsFormValid] = useState(false);
const templateData1 = useSelector(getTemplateData);
const selthemeData = useSelector(getThemeCreation);
console.log(selthemeData, templateData1, 'themeData111111111');
const LayoutOverallbackgroundlist = useSelector(
GlobalLayoutOverallbackgroundlist
);
const SubcategoryOverallColorsList = useSelector(
GlobalSubcategoryOverallColorsList
);
const CategoryOverallColorsList = useSelector(
GlobalCategoryOverallColorsList
);
const cardOverallColorsList = useSelector(GlobalcardOverallColorsList);
const BillingOverallColorsList = useSelector(GlobalBillingOverallColorsList);
const CatColorData = useSelector(getColorsDataCat);
const SubcatColorData = useSelector(getColorsDataSubcat);
const CardColorData = useSelector(getColorsDataCard);
const TableColorData = useSelector(getColorsDataBilltable);
const CatFontData = useSelector(GlobalCatData);
const SubCatFontData = useSelector(GlobalSubcatData);
const CardFontData = useSelector(GlobalCardData);
const TableFontData = useSelector(GlobalTableData);
const SelectedCardFont = useSelector(SelectedGlobalCardFont);
const SelectedBillingFont = useSelector(SelectedGlobalBillingFont);
const SelectedCatgFont = useSelector(SelectedGlobalCatgFont);
const SelectedSubCatgFont = useSelector(SelectedGlobalSubCatgFont);
const EditColor = useSelector(selectedColorId);
const EditFont = useSelector(selectedFontId);
const GlobalCardColorDetail = useSelector(SelectedGlobalCardColorDetail);
const GlobalBillingColorDetail = useSelector(
SelectedGlobalBillingColorDetail
);
const GlobalCatgColorDetail = useSelector(SelectedGlobalCatgColorDetail);
const GlobalSubCatgColorDetail = useSelector(
SelectedGlobalSubCatgColorDetail
);
const DefaultThemes = useSelector(GlobalDefaultTheme);
const SelectedTheme = useSelector(GlobalSelectedTheme)
const activeTheme = useSelector(GlobalActiveTheme);
const appPreferences = useSelector(ApplicationPreferences);
const bookingTypePreference = appPreferences?.find((preference) => preference?.PreferredCatName === 'Booking Type')?.PreferenceCatDetails
const dinePreference = bookingTypePreference?.find((type) => type?.PreferredSubCatName?.toLowerCase() === "dine in" && type?.PreferredStatus === 'Y')
const takeAwayPreference = bookingTypePreference?.find((type) => type?.PreferredSubCatName?.toLowerCase() === "take away" && type?.PreferredStatus === 'Y')
const AppId = getSession('AppId');
const UserId = getSession('UserId');
const CompId = getSession('CompId');
const BranchId = getSession('BranchId');
const UserType = getSession('UserType');
const [Temptemplatedata, setTemptemplatedata] = useState(false);
const [GlobalPreferenceData, setGlobalPreferenceData] = useState([]);
const [selectedCatFont, setSelectedCatFont] = useState();
const [selectedSubCatFont, setSelectedSubcatFont] = useState();
const [selectedCardFont, setSelectedCardFont] = useState();
const [selectedTableFont, setSelectedTableFont] = useState();
const [UploadColor, setUploadColor] = useState(false);
const [BillUploadColor, BillsetUploadColor] = useState(false);
const [UploadColorselectcard, setUploadColorselectcard] = useState(false);
const [UploadLayoutOverallBackground, setUploadLayoutOverallBackground] =
useState(false);
const [CategoryUploadOverallColor, setCategoryUploadOverallColor] =
useState(false);
const [SubcategoryUploadOverallColor, setSubcategoryUploadOverallColor] =
useState(false);
const [cardUploadOverallColor, setcardUploadOverallColor] = useState(false);
const [BillingUploadOverallColor, setBillingUploadOverallColor] =
useState(false);
const [UploadColorsubcat, setUploadColorsubcat] = useState(false);
const [catModelOpen, setcatModelOpen] = useState(false);
const [subCatModelopen, setSubCatModelopen] = useState(false);
const [CardModelopen, setCardModelopen] = useState(false);
const [TableModelopen, setTableModelopen] = useState(false);
const [messageType, setMessageType] = useState(null);
const [messageData, setMessageData] = useState(null);
// Dropdowndatas state
const [LayoutData, setLayoutData] = useState([]);
const [NavbarData, setNavbarData] = useState([]);
const [CategoryData, setCategoryData] = useState([]);
const [SubCategoryData, setSubCategoryData] = useState([]);
const [CardData, setCardData] = useState([]);
const [BillingTableData, setBillingTableData] = useState([]);
// selected Dropdown ids
const [currentLayoutsessionID, setCurrentLayoutsessionID] = useState(null);
const [SelectedLayoutId, setSelectedLayoutId] = useState(null);
const [SelectedNavbarId, setSelectedNavbarId] = useState(null);
const [SelectedCategoryId, setSelectedCategoryId] = useState(null);
const [SelectedSubCategoryId, setSelectedSubCategoryId] = useState(null);
const [SelectedCardId, setSelectedCardId] = useState(null);
const [SelectedBillingTableId, setSelectedBillingTableId] = useState(null);
const [ShowDropDownData, SetShowDropDownData] = useState([]);
//navbarcheck boxes
const [NavBarCheckList, setNavBarCheckList] = useState([]);
const [SelectedNavCheckValues, setSelectedNavCheckValues] = useState([]);
const [SelectedNavCheckList, setSelectedNavCheckList] = useState([]);
const DineInChecked = SelectedNavCheckValues?.includes(
NavBarCheckList?.[0]?.ComponentOptionsDetails?.filter(
(item) => item?.OptionName === 'DineIn'
)?.[0]?.OptionId
);
//categorycheckbox
const [CategoryCheckList, setCategoryCheckList] = useState([]);
const [SelectedCategoryCheckValues, setSelectedCategoryCheckValues] =
useState([]);
const [SelectedCategoryCheckList, setSelectedCategoryCheckList] = useState(
[]
);
// Subcategorycheckbox
const [SubCategoryCheckList, setSubCategoryCheckList] = useState([]);
const [SelectedSubCategoryCheckValues, setSelectedSubCategoryCheckValues] =
useState([]);
const [SelectedSubCategoryCheckList, setSelectedSubCategoryCheckList] =
useState([]);
//Cardcheck boxes
const [CardCheckList, setCardCheckList] = useState([]);
const [SelectedCardCheckValues, setSelectedCardCheckValues] = useState([]);
const [SelectedCardCheckList, setSelectedCardCheckList] = useState([]);
// BillingTable
const [BillTableCheckList, setBillTableCheckList] = useState([]);
const [SelectedBillTableCheckValues, setSelectedBillTableCheckValues] =
useState([]);
const [SelectedBillTableCheckList, setSelectedBillTableCheckList] = useState(
[]
);
// Hold and addcustomer OptionsDetails
const [HoldButton, setHoldButton] = useState(false);
const [AddCustomerButton, setAddCustomerButton] = useState(false);
// nav hold option
const [NavHoldButton, setNavHoldButton] = useState(false);
const [NavAddCustomerButton, setNavAddCustomerButton] = useState(false);
// category Image Selection
const [CatImageSelection, setCatImageSelection] = useState(false);
const [CatbackgroundSelection, setCatbackgroundSelection] = useState(false);
const [CardSelection, setCardSelection] = useState(false);
const [BillbackgroundSelection, setBillbackgroundSelection] = useState(false);
const [SmallImage, setSmallImage] = useState(false);
const [SelectAllPositionImage, setSelectAllPositionImage] = useState([]);
const [SelectfliterPositionImage, setSelectfliterPositionImage] =
useState(false);
const [SelectedTableColor, setSelectedTableColor] = useState(null);
const [SelectedCardColor, setSelectedCardColor] = useState(null);
const [SelectedSubCatColor, setSelectedSubCatColor] = useState(null);
const [SelectedCatColor, setSelectedCatColor] = useState(null);
const [dropdownLayoutOverallColor, setdropdownLayoutOverallColor] =
useState(null);
const [dropdownCategoryOverallColor, setdropdownCategoryOverallColor] =
useState(null);
const [dropdownSubcategoryOverallColor, setdropdownSubcategoryOverallColor] =
useState(null);
const [dropdownCardOverallColor, setdropdownCardOverallColor] =
useState(null);
const [dropdownBillingOverallColor, setdropdownBillingOverallColor] =
useState(null);
const [CatColorType, setcatColorType] = useState('Y');
const [CardColorType, setCardColorType] = useState('Y');
const [SubCatColorType, setSubCatColorType] = useState('Y');
const [TableColorType, setTableColorType] = useState('Y');
const [CatfontColor, setCatfontColor] = useState('#000000');
const [catFontHex, setCatFontHex] = useState(
CatfontColor?.replace('#', '').trim()
);
const [SubcatfontColor, setSubcatfontColor] = useState('#000000');
const [subCatFontHex, setSubCatFontHex] = useState(
SubcatfontColor?.replace('#', '').trim()
);
const [TablefontColor, setTablefontColor] = useState('#000000');
const [tableFontHex, setTableFontHex] = useState(
TablefontColor?.replace('#', '').trim()
);
const [CardfontColor, setCardfontColor] = useState('#000000');
const [cardFontHex, setCardFontHex] = useState(
CardfontColor?.replace('#', '').trim()
);
const [CatbackgroundColor, setCatbackgroundColor] = useState('#009b00');
const [catBGHex, setCatBGHex] = useState(
CatbackgroundColor?.replace('#', '').trim()
);
const [SubcatbackgroundColor, setSubcatbackgroundColor] = useState('#009b00');
const [subCatBGHex, setSubCatBGHex] = useState(
SubcatbackgroundColor?.replace('#', '').trim()
);
const [CardbackgroundColor, setCardbackgroundColor] = useState('#009b00');
const [cardBGHex, setCardBGHex] = useState(
CardbackgroundColor?.replace('#', '').trim()
);
const [TablebackgroundColor, setTablebackgroundColor] = useState('#009b00');
const [tableBGHex, setTableBGHex] = useState(
TablebackgroundColor?.replace('#', '').trim()
);
const [LayoutOverallColor, setLayoutOverallColor] = useState('#000000');
const [layoutOverallHexCode, setLayoutOverallHexCode] = useState(
LayoutOverallColor?.replace('#', '').trim()
);
const [CategoryOverallColor, setCategoryOverallColor] = useState('#000000');
const [categoryOverallHex, setCategoryOverallHex] = useState(
CategoryOverallColor?.replace('#', '').trim()
);
const [SubcategoryOverallColor, setSubcategoryOverallColor] =
useState('#000000');
const [subCatOverallHex, setSubCatOverallHex] = useState(
SubcategoryOverallColor?.replace('#', '').trim()
);
const [CardOverallColor, setCardOverallColor] = useState('#000000');
const [cardOverallHex, setCardOverallHex] = useState(
CardOverallColor?.replace('#', '').trim()
);
const [BillingOverallColor, setBillingOverallColor] = useState('#000000');
const [billingOverallHex, setBillingOverallHex] = useState(
BillingOverallColor?.replace('#', '').trim()
);
const [selectOverallSelected, setSelectOverallSelected] = useState(true);
const [empData, setEmpData] = useState();
const [addnewAccess, setaddnewAccess] = useState(true);
// const [activeTheme, setActiveTheme] = useState(
// Object.keys(templateData1)?.length > 0 ? 'customised' : 'default'
// );
const [ThemesData, setThemesData] = useState([]);
const [templateData, settemplateData] = useState({});
console.log(DefaultThemes, 'ThemesDataThemesData');
// const [SelectedTheme, setSelectedTheme] = useState(null);
console.log(SelectedTheme, 'SelectedThemeSelectedTheme');
const [FirstOnClick, setFirstOnClick] = useState(false);
const [isNext, isSetNext] = useState(true);
const items = [
{
name: 'Home',
link: `${subDirectory}app-page/home`,
},
// {
// name: "SalesSetup",
// link: `${subDirectory}saleslayouts/sales-selection`,
// },
];
useImperativeHandle(ref, () => ({
submit: () => {
form.submit(); // Triggers the onFinish callback
},
}));
useEffect(() => {
dispatch(changeThemeCreation({ formtype: 'new' }));
dispatch(changeSelectedTheme(null));
dispatch(changeBreadCrumb({ items: items }));
gettemplatedetail();
GetPreferenceDetails();
// if (UserType === "Employee") {
// fetchApi()
// }
getThemesData();
}, []);
useEffect(() => {
if (activeTheme == 'default') {
if (Object.keys(DefaultThemes)?.length > 0) {
dispatch(changeSelectedTheme({ ThemeId: DefaultThemes?.[0]?.TemplatePreferenceId, ThemeName: DefaultThemes?.[0]?.ThemeName }));
settemplateData(DefaultThemes?.[0]);
dispatch(changeThemeCreation({ formtype: 'edit', editdata: DefaultThemes?.[0] }));
} else {
dispatch(changeSelectedTheme({}));
settemplateData({});
}
}
}, [DefaultThemes, activeTheme]);
useEffect(() => {
if (UserType === 'Employee') {
fetchApi();
}
}, [UserType]);
useEffect(() => {
let hasAccess = false;
if (UserType === 'Admin' || UserType === 'Super Admin') {
hasAccess = true;
} else if (UserType === 'Employee') {
hasAccess =
empData?.AddAccess === 'Y' ||
SAAccessCommonMaster?.UpdateAccess === 'Y';
} else if (UserType === 'Super Admin User') {
hasAccess =
SAAccessCommonMaster?.AddAccess === 'Y' ||
SAAccessCommonMaster?.UpdateAccess === 'Y';
}
setaddnewAccess(!hasAccess);
}, [empData, SAAccessCommonMaster, UserType]);
const gettemplatedetail = async () => {
let tempdetail = await dispatch(
getTemplate({ CompId: CompId, BranchId: BranchId, AppId: AppId })
).unwrap();
if (tempdetail?.data?.statusCode == 1) {
dispatch(changeActiveTheme("customised"));
} else {
setTemptemplatedata(true);
}
};
const fetchApi = async () => {
let data = {
CompId: CompId,
BranchId: BranchId,
AppId: AppId,
EmpId: UserId,
};
let response = await dispatch(getEmpAccess(data)).unwrap();
let datas = response?.data?.data?.[0]?.EmpAccessDetails?.filter(
(item) => item.ConfigName === 'Sales Screen'
);
setEmpData(datas?.[0]);
};
const getThemesData = async () => {
// let themeresponse =
await dispatch(getThemes()).unwrap();
// if (themeresponse.data?.statusCode === 1) {
// let themedatalist = themeresponse.data?.data?.filter(
// (item) => item?.ActiveStatus == 'A'
// );
// if (themedatalist?.length > 0) {
// // setThemesData(themedatalist);
// // console.log(themedatalist, 'themedatalist');
// // dispatch(changeThemeCreation({ formtype: 'edit', editdata: themedatalist?.[0] }));
// // setSelectedTheme(themedatalist?.[0]?.TemplatePreferenceId);
// } else {
// // GetOthersTemplate();
// }
// } else {
// setThemesData([]);
// }
};
useEffect(() => {
// if(Object.keys(templateData1)?.length > 0){
// settemplateData(templateData1)
// }else{
if (activeTheme == 'default') {
if (Object.keys(selthemeData)?.length > 0) {
settemplateData(selthemeData);
} else {
settemplateData({});
}
} else {
settemplateData(templateData1);
// }
}
}, [templateData1, selthemeData, activeTheme]);
useEffect(() => {
if (Object.keys(templateData)?.length > 0) {
setEditTemplateData();
} else {
ClearAllComponentStates();
}
}, [templateData]);
useEffect(() => {
const Unpaidchecked =
BillTableCheckList?.[0]?.ComponentOptionsDetails?.find(
(item) => item?.OptionName === 'UnpaidBill'
)?.OptionId;
if (!DineInChecked && Unpaidchecked) {
setSelectedBillTableCheckList((prevList) =>
prevList?.filter((item) => item.OptionId !== Unpaidchecked)
);
setSelectedBillTableCheckValues((prevValues) =>
prevValues?.filter((item) => item !== Unpaidchecked)
);
let obj = SelectedBillTableCheckList?.filter(
(item) => item.OptionId !== Unpaidchecked
);
dispatch(changeSelectedBillTableCheckedItems(obj));
}
}, [DineInChecked]);
const ClearAllComponentStates = () => {
GetLayoutFun();
setBillbackgroundSelection(!BillbackgroundSelection);
setCatbackgroundSelection(!CatbackgroundSelection);
setCardSelection(!CardSelection);
setSelectedLayoutId(null);
setSelectedNavbarId(null);
setNavBarCheckList([]);
setSelectedNavCheckValues([]);
setSelectedNavCheckList([]);
setSelectedCategoryId(null);
setCategoryCheckList([]);
setSelectedCategoryCheckValues([]);
setSelectedCategoryCheckList([]);
setSelectedSubCategoryId(null);
setSelectedSubCategoryCheckValues([]);
setSubCategoryCheckList([]);
setSelectedSubCategoryCheckList([]);
setSelectedCardId(null);
setCardCheckList([]);
setSelectedCardCheckValues([]);
setSelectedCardCheckList([]);
setSelectedBillingTableId(null);
setBillTableCheckList([]);
setSelectedBillTableCheckValues([]);
setSelectedBillTableCheckList([]);
setHoldButton(false);
setAddCustomerButton(false);
setNavHoldButton(false);
setNavAddCustomerButton(false);
setCatImageSelection(false);
setSelectedTableColor(null);
setSelectedCardColor(null);
setSelectedSubCatColor(null);
setSelectedCatColor(null);
setdropdownLayoutOverallColor(null);
setdropdownSubcategoryOverallColor(null);
setdropdownCardOverallColor(null);
setdropdownBillingOverallColor(null);
formRef.current.resetFields();
dispatch(changePreviewComponents({}));
};
const GetPreferenceDetails = async () => {
let Preference = await dispatch(
getPreferenceData({ CompId: CompId, BranchId: BranchId, AppId: AppId })
).unwrap();
if (Preference?.data?.statusCode === 1) {
let Prefencedata = Preference?.data?.data?.[0]?.[
'SettingDtlDetails'
]?.find((item) => item.SettingIdName === 'DineIn');
setGlobalPreferenceData(Prefencedata);
} else {
setGlobalPreferenceData();
}
};
const setEditTemplateData = async () => {
if (Object.keys(templateData)?.length > 0) {
let gettingEditLayOutData = await dispatch(getLayout()).unwrap();
if (gettingEditLayOutData?.data?.statusCode === 1) {
setLayoutData(gettingEditLayOutData.data?.data);
const editLayoutVal = gettingEditLayOutData.data?.data?.filter(
(item) => item.ComponentName == templateData?.['BookingLayout']?.[0]
);
formRef?.current?.setFieldsValue({
LayoutId: editLayoutVal?.[0]?.['ComponentId'],
});
setSelectedLayoutId(editLayoutVal?.[0]?.['ComponentId']);
selectLayout(editLayoutVal?.[0]?.['ComponentId']);
if (editLayoutVal?.[0]?.ComponentName === 'Combo1') {
GetCombo1Navbar();
} else if (editLayoutVal?.[0]?.ComponentName === 'Combo2') {
GetCombo2Navbar();
}
dispatch(
changePreviewComponents({
BookingLayout: [
editLayoutVal[0]?.ComponentName,
editLayoutVal[0]?.ComponentOptionsDetails,
],
})
);
let Imageselection = templateData?.['BookingCategory']?.[1]?.filter(
(a) => a.OptionName === 'Image'
);
if (Imageselection?.length > 0) {
setCatImageSelection(true);
} else {
setCatImageSelection(false);
}
let smallImageSelection = templateData?.['BookingCard']?.[1]?.filter(
(a) => a.OptionName === 'SmallImage'
);
if (smallImageSelection?.length) {
setSmallImage(true);
}
}
}
};
useEffect(() => {
if (templateData && NavbarData?.length > 0) {
if (templateData?.BookingLayout?.[0] === 'Combo2') {
let editNavbarVal = NavbarData?.filter(
(item) => item.ComponentName == templateData?.['BookingCombo2']?.[0]
);
selectNavbar(editNavbarVal?.[0]?.['ComponentId']);
const optionIds = templateData?.['BookingCombo2']?.[1]?.map(
(item) => item?.OptionId
);
NavBarSelectlistonChange(optionIds);
} else if (templateData?.BookingLayout?.[0] === 'Combo1') {
let editNavbarVal = NavbarData?.filter(
(item) => item.ComponentName == templateData?.['BookingCombo1']?.[0]
);
selectNavbar(editNavbarVal?.[0]?.['ComponentId']);
const optionIds = templateData?.['BookingCombo1']?.[1]?.map(
(item) => item?.OptionId
);
NavBarSelectlistonChange(optionIds);
} else {
let editNavbarVal = NavbarData?.filter(
(item) => item.ComponentName == templateData?.['BookingNavbar']?.[0]
);
selectNavbar(editNavbarVal?.[0]?.['ComponentId']);
const optionIds = templateData?.['BookingNavbar']?.[1]?.map(
(item) => item?.OptionId
);
NavBarSelectlistonChange(optionIds);
}
}
}, [NavbarData]);
useEffect(() => {
if (templateData && CategoryData?.length > 0) {
const editCategoryrVal = CategoryData?.filter(
(item) => item.ComponentName == templateData?.['BookingCategory']?.[0]
);
if (
CategoryData[0]?.SessionId != null &&
CategoryData[0]?.SessionId != undefined
) {
let OverallCategorydata = {
SessionID: CategoryData[0]?.SessionId,
OptionName: 'OverallBackground',
};
dispatch(getCategoryOverallBackgroundColors(OverallCategorydata))
.unwrap;
}
if (
CategoryData[0]?.SessionId != null &&
CategoryData[0]?.SessionId != undefined
) {
let Categorydata = {
SessionID: CategoryData[0]?.SessionId,
OptionName: 'Background',
};
dispatch(getColorsCat(Categorydata)).unwrap;
}
dispatch(getCatFonts(CategoryData[0]?.SessionId)).unwrap;
selectCategory(editCategoryrVal?.[0]?.['ComponentId']);
let optionIds = templateData?.['BookingCategory']?.[1]?.map(
(item) => item?.OptionId
);
CategorySelectlistonChange(optionIds);
}
}, [CategoryData]);
useEffect(() => {
if (templateData && SubCategoryData?.length > 0) {
const editSubCategoryrVal = SubCategoryData?.filter(
(item) =>
item.ComponentName == templateData?.['BookingSubCategory']?.[0]
);
if (
SubCategoryData[0]?.SessionId != null &&
SubCategoryData[0]?.SessionId != undefined
) {
let OveralSubCategorydata = {
SessionID: SubCategoryData[0]?.SessionId,
OptionName: 'OverallBackground',
};
dispatch(getSubcategoryOverallBackgroundColors(OveralSubCategorydata))
.unwrap;
}
if (
SubCategoryData[0]?.SessionId != null &&
SubCategoryData[0]?.SessionId != undefined
) {
let SubCategorydata = {
SessionID: SubCategoryData[0]?.SessionId,
OptionName: 'Background',
};
dispatch(getColorsSubcat(SubCategorydata)).unwrap;
}
selectSubCategory(editSubCategoryrVal?.[0]?.['ComponentId']);
let optionIds = templateData?.['BookingSubCategory']?.[1]?.map(
(item) => item?.OptionId
);
SubCategorySelectlistonChange(optionIds);
}
}, [SubCategoryData]);
useEffect(() => {
if (templateData && CardData?.length > 0) {
let editCardVal = CardData?.filter(
(item) => item.ComponentName == templateData?.['BookingCard']?.[0]
);
if (
CardData[0]?.SessionId != null &&
CardData[0]?.SessionId != undefined
) {
let OverallCarddata = {
SessionID: CardData[0]?.SessionId,
OptionName: 'OverallBackground',
};
dispatch(getCardOverallBackgroundColors(OverallCarddata)).unwrap;
}
if (
CardData[0]?.SessionId != null &&
CardData[0]?.SessionId != undefined
) {
let Carddata = {
SessionID: CardData[0]?.SessionId,
OptionName: 'Background',
};
dispatch(getColorsCard(Carddata)).unwrap;
}
selectCard(editCardVal?.[0]?.['ComponentId']);
const optionIds = templateData?.['BookingCard']?.[1]?.map(
(item) => item?.OptionId
);
CardSelectlistonChange(optionIds);
}
}, [CardData]);
useEffect(() => {
if (templateData && BillingTableData?.length > 0) {
console.log(BillingTableData?.length, "BillingTableData?.length")
const editCardVal = BillingTableData?.filter(
(item) => item.ComponentName == templateData?.['BookingBilling']?.[0]
);
if (
BillingTableData[0]?.SessionId != null &&
BillingTableData[0]?.SessionId != undefined
) {
let OverallBillingdata = {
SessionID: BillingTableData[0]?.SessionId,
OptionName: 'OverallBackground',
};
dispatch(getBillingOverallBackgroundColors(OverallBillingdata)).unwrap;
}
if (
BillingTableData[0]?.SessionId != null &&
BillingTableData[0]?.SessionId != undefined
) {
let Billingdata = {
SessionID: BillingTableData[0]?.SessionId,
OptionName: 'Background',
};
dispatch(getColorsBilltable(Billingdata)).unwrap;
}
selectBillingTable(editCardVal?.[0]?.['ComponentId']);
const optionIds = templateData?.['BookingBilling']?.[1]?.map(
(item) => item?.OptionId
);
BillTableSelectlistonChange(optionIds);
}
}, [BillingTableData]);
useEffect(() => {
if (templateData && CategoryData?.length > 0) {
EditColor?.filter(
(item) => item.SessionName === 'BookingCategory'
)?.forEach((item) => {
if (item?.['BackgroundColor']) {
formRef?.current?.setFieldsValue({ CatColor: item?.['ColorId'] });
setSelectedCatColor(item?.['ColorId']);
} else if (item?.['OverallBackgroundColor']) {
formRef?.current?.setFieldsValue({
CatOverallColor: item?.['ColorId'],
});
setdropdownCategoryOverallColor(item?.['ColorId']);
dispatch(
changeSelectedCatgColorDetail({
catgColor: {
BackgroundColor: GlobalCatgColorDetail?.['BackgroundColor'],
FontColor: GlobalCatgColorDetail?.['FontColor'],
OverallBackgroundColor: CategoryOverallColorsList?.filter(
(data) => data?.ColorId === item?.['ColorId']
)?.[0]?.['BackgroundColor'],
},
})
);
}
});
}
}, [CatColorData, CategoryOverallColorsList]);
useEffect(() => {
if (templateData && SubCategoryData?.length > 0) {
EditColor?.filter(
(item) => item.SessionName === 'BookingSubCategory'
)?.forEach((item) => {
if (item?.['BackgroundColor']) {
formRef?.current?.setFieldsValue({ SubCatColor: item?.['ColorId'] });
setSelectedSubCatColor(item?.['ColorId']);
} else if (item?.['OverallBackgroundColor']) {
formRef?.current?.setFieldsValue({
SubCatOverallColor: item?.['ColorId'],
});
setdropdownSubcategoryOverallColor(item?.['ColorId']);
dispatch(
changeSelectedSubCatgColorDetail({
subCatgColor: {
BackgroundColor: GlobalSubCatgColorDetail?.['BackgroundColor'],
FontColor: GlobalSubCatgColorDetail?.['FontColor'],
OverallBackgroundColor: SubcategoryOverallColorsList?.filter(
(data) => data?.ColorId === item?.['ColorId']
)?.[0]?.['BackgroundColor'],
},
})
);
}
});
}
}, [SubcatColorData, SubcategoryOverallColorsList]);
useEffect(() => {
if (templateData && CardData?.length > 0) {
EditColor?.filter((item) => item.SessionName === 'BookingCard')?.forEach(
(item) => {
if (item?.['BackgroundColor']) {
formRef?.current?.setFieldsValue({ CardColor: item?.['ColorId'] });
setSelectedCardColor(item?.['ColorId']);
} else if (item?.['OverallBackgroundColor']) {
formRef?.current?.setFieldsValue({
CardOverallColor: item?.['ColorId'],
});
setdropdownCardOverallColor(item?.['ColorId']);
dispatch(
changeSelectedCardColorDetail({
cardColor: {
BackgroundColor: GlobalCardColorDetail?.['BackgroundColor'],
FontColor: GlobalCardColorDetail?.['FontColor'],
OverallBackgroundColor: cardOverallColorsList?.filter(
(data) => data?.ColorId === item?.['ColorId']
)?.[0]?.['BackgroundColor'],
},
})
);
}
}
);
}
}, [CardColorData, cardOverallColorsList]);
useEffect(() => {
if (templateData && BillingTableData?.length > 0) {
EditColor?.filter(
(item) => item.SessionName === 'BookingBilling'
)?.forEach((item) => {
if (item?.['BackgroundColor']) {
formRef?.current?.setFieldsValue({ TableColor: item?.['ColorId'] });
setSelectedTableColor(item?.['ColorId']);
} else if (item?.['OverallBackgroundColor']) {
formRef?.current?.setFieldsValue({
BillingOverallColor: item?.['ColorId'],
});
setdropdownBillingOverallColor(item?.['ColorId']);
dispatch(
changeSelectedBillingColorDetail({
billingColor: {
BackgroundColor: GlobalBillingColorDetail?.['BackgroundColor'],
FontColor: GlobalBillingColorDetail?.['FontColor'],
OverallBackgroundColor: BillingOverallColorsList?.filter(
(data) => data?.ColorId === item?.['ColorId']
)?.[0]?.['BackgroundColor'],
},
})
);
}
});
}
}, [TableColorData, BillingOverallColorsList]);
useEffect(() => {
if (Object.keys(templateData)?.length > 0) {
const bookingLayoutColors = EditColor?.filter(
(item) => item.SessionName === 'BookingLayout'
);
if (bookingLayoutColors.length > 0) {
bookingLayoutColors.forEach((item) => {
if (item?.['OverallBackgroundColor']) {
formRef?.current?.setFieldsValue({
LayoutOverallBackground: item?.['ColorId'],
});
setdropdownLayoutOverallColor(item?.['ColorId']);
}
});
} else {
// Reset the values when "BookingLayout" is not found
formRef?.current?.resetFields(['LayoutOverallBackground']);
setdropdownLayoutOverallColor(null);
}
}
}, [LayoutOverallbackgroundlist]);
useEffect(() => {
if (templateData && CategoryData?.length > 0) {
let FontCat = EditFont?.find(
(item) => item.SessionName === 'BookingCategory'
)?.['FontId'];
formRef?.current?.setFieldsValue({ FontCat: FontCat });
setSelectedCatFont(FontCat);
}
}, [CatFontData]);
useEffect(() => {
if (templateData && SubCategoryData?.length > 0) {
let FontSubCat = EditFont?.find(
(item) => item.SessionName === 'BookingSubCategory'
)?.['FontId'];
formRef?.current?.setFieldsValue({ FontSubcat: FontSubCat });
setSelectedSubcatFont(FontSubCat);
}
}, [SubCatFontData]);
useEffect(() => {
if (templateData && CardData?.length > 0) {
let FontCard = EditFont?.find(
(item) => item.SessionName === 'BookingCard'
)?.['FontId'];
formRef?.current?.setFieldsValue({ FontCard: FontCard });
setSelectedCardFont(FontCard);
}
}, [CardFontData]);
useEffect(() => {
if (templateData && BillingTableData?.length > 0) {
let FontTable = EditFont?.find(
(item) => item.SessionName === 'BookingBilling'
)?.['FontId'];
formRef?.current?.setFieldsValue({ FontTable: FontTable });
setSelectedTableFont(FontTable);
}
}, [TableFontData]);
useEffect(
() => {
if (SelectedCardFont) {
WebFont.load({
google: {
families: [SelectedCardFont], // Load the selected font
},
});
}
if (SelectedBillingFont) {
WebFont.load({
google: {
families: [SelectedBillingFont], // Load the selected font
},
});
}
if (SelectedCatgFont) {
WebFont.load({
google: {
families: [SelectedCatgFont], // Load the selected font
},
});
}
if (SelectedSubCatgFont) {
WebFont.load({
google: {
families: [SelectedSubCatgFont], // Load the selected font
},
});
}
},
[SelectedCardFont],
[SelectedBillingFont],
[SelectedCatgFont],
[SelectedSubCatgFont]
);
useEffect(() => {
GetLayoutBackgroundFun();
let DrpData = LayoutData?.filter((a) => a.ComponentId === SelectedLayoutId);
SetShowDropDownData(DrpData?.[0]?.ComponentOptionsDetails);
if (DrpData?.[0]?.ComponentName === 'Combo1') {
GetCombo1Navbar();
} else if (DrpData?.[0]?.ComponentName === 'Combo2') {
GetCombo2Navbar();
}
}, [SelectedLayoutId]);
// Function to check form validation
const checkFormValidity = () => {
formRef?.current
?.validateFields()
.then(() => setIsFormValid(true))
.catch(() => setIsFormValid(false));
};
// Run validation whenever form values change
const onValuesChange = () => {
checkFormValidity();
};
// const changeThemes = (theme) => {
// setSelectedTheme(theme.TemplatePreferenceId);
// };
const GetLayoutFun = async () => {
const gettingLayOutData = await dispatch(getLayout()).unwrap();
if (gettingLayOutData?.data?.statusCode === 1) {
setLayoutData(gettingLayOutData?.data?.data);
setCurrentLayoutsessionID(gettingLayOutData?.data?.data?.[0]?.SessionId);
}
};
// Get Dropdown datas
const GetLayoutBackgroundFun = async () => {
if (currentLayoutsessionID != null && currentLayoutsessionID != undefined) {
let OverallLayoutdata = {
SessionID: currentLayoutsessionID,
OptionName: 'OverallBackground',
};
await dispatch(
getLayoutOverallBackgroundColors(OverallLayoutdata)
).unwrap();
}
};
const GetNavbarFun = async () => {
const gettingNavbarData = await dispatch(getNavbar()).unwrap();
if (gettingNavbarData?.data?.statusCode === 1) {
setNavbarData(gettingNavbarData.data?.data?.map((navbar) => {
return {
...navbar,
ComponentOptionsDetails: navbar?.ComponentOptionsDetails
?.filter((component) =>
!((component?.OptionName === 'DineIn' && dinePreference === undefined) ||
(component?.OptionName === 'TakeAway' && takeAwayPreference === undefined))
)
}
}));
}
};
const GetCategoryFun = async () => {
const gettingCategoryData = await dispatch(getCategory()).unwrap();
if (gettingCategoryData?.data?.statusCode === 1) {
dispatch(getCatFonts(gettingCategoryData?.data?.data?.[0]?.SessionId))
.unwrap;
setCategoryData(gettingCategoryData?.data?.data);
}
};
const GetSubCategoryFun = async () => {
const gettingSubCategoryData = await dispatch(getSubCategory()).unwrap();
if (gettingSubCategoryData?.data?.statusCode === 1) {
dispatch(
getSubCatFonts(gettingSubCategoryData?.data?.data?.[0]?.SessionId)
).unwrap;
setSubCategoryData(gettingSubCategoryData?.data?.data);
}
};
const GetCardFun = async () => {
const gettingCardData = await dispatch(getCard()).unwrap();
if (gettingCardData?.data?.statusCode === 1) {
dispatch(getCardFonts(gettingCardData?.data?.data?.[0]?.SessionId))
.unwrap;
setCardData(gettingCardData?.data?.data);
let tempcarddata = gettingCardData?.data?.data;
let CardItems = tempcarddata?.filter((a) => a.ComponentName === 'Card2');
let ImagePosition = CardItems[0]?.ComponentOptionsDetails?.filter(
(e) =>
e.OptionName.includes('Image') &&
!e.OptionName.includes('SmallImage') &&
!e.OptionName.includes('BigImage')
);
let ImagePositionId = ImagePosition?.map((d) => d?.OptionId);
setSelectAllPositionImage(ImagePositionId);
setSelectfliterPositionImage(ImagePositionId);
}
};
const GetBillingTableFun = async () => {
const gettingBillingTableData = await dispatch(getBillingTable()).unwrap();
if (gettingBillingTableData?.data?.statusCode === 1) {
dispatch(
getTableFonts(gettingBillingTableData?.data?.data?.[0]?.SessionId)
).unwrap;
setBillingTableData(gettingBillingTableData?.data?.data);
}
};
const GetCombo1Navbar = async () => {
const gettingCombo1NavbarData = await dispatch(getCombo1Navbar()).unwrap();
if (gettingCombo1NavbarData?.data?.statusCode === 1) {
setNavbarData(gettingCombo1NavbarData?.data?.data?.map((navbar) => {
return {
...navbar,
ComponentOptionsDetails: navbar?.ComponentOptionsDetails
?.filter((component) =>
!((component?.OptionName === 'DineIn' && dinePreference === undefined) ||
(component?.OptionName === 'TakeAway' && takeAwayPreference === undefined))
)
}
}));
}
};
const GetCombo2Navbar = async () => {
const gettingCombo2NavbarData = await dispatch(getCombo2Navbar()).unwrap();
if (gettingCombo2NavbarData?.data?.statusCode === 1) {
setNavbarData(gettingCombo2NavbarData?.data?.data?.map((navbar) => {
return {
...navbar,
ComponentOptionsDetails: navbar?.ComponentOptionsDetails
?.filter((component) =>
!((component?.OptionName === 'DineIn' && dinePreference === undefined) ||
(component?.OptionName === 'TakeAway' && takeAwayPreference === undefined))
)
}
}));
}
};
// Selected value functions
const selectLayout = (e) => {
formRef.current?.setFieldsValue({ LayoutId: e });
setSelectedLayoutId(e);
dispatch(
changeSelectedLayout({
LayoutId: e,
})
);
let LayoutValues = LayoutData?.filter((item) => item.ComponentId == e);
dispatch(
changePreviewComponents({
BookingLayout: [
LayoutValues[0]?.ComponentName,
LayoutValues[0]?.ComponentOptionsDetails,
],
})
);
GetNavbarFun();
GetLayoutBackgroundFun();
GetCategoryFun();
GetCardFun();
GetSubCategoryFun();
GetBillingTableFun();
setSelectedNavbarId(null);
setNavBarCheckList([]);
setSelectedNavCheckValues([]);
setSelectedNavCheckList([]);
setSelectedCategoryId(null);
setCategoryCheckList([]);
setSelectedCategoryCheckValues([]);
setSelectedCategoryCheckList([]);
setSelectedSubCategoryId(null);
setSelectedSubCategoryCheckValues([]);
setSubCategoryCheckList([]);
setSelectedSubCategoryCheckList([]);
setSelectedCardId(null);
setCardCheckList([]);
setSelectedCardCheckValues([]);
setSelectedCardCheckList([]);
setSelectedBillingTableId(null);
setBillTableCheckList([]);
setSelectedBillTableCheckValues([]);
setSelectedBillTableCheckList([]);
setHoldButton(false);
setAddCustomerButton(false);
setNavHoldButton(false);
setNavAddCustomerButton(false);
let Imageselection = templateData?.['BookingCategory']?.[1]?.filter(
(a) => a.OptionName === 'Image'
);
if (Imageselection?.length > 0) {
setCatImageSelection(true);
} else {
setCatImageSelection(false);
}
formRef.current.resetFields(['NavbarId']);
formRef.current.resetFields(['CategoryId']);
formRef.current.resetFields(['SubCategoryId']);
formRef.current.resetFields(['CardId']);
formRef.current.resetFields(['BillingTableId']);
};
const selectNavbar = (e) => {
formRef.current?.setFieldsValue({ NavbarId: e });
setSelectedNavbarId(e);
dispatch(changeSelectedNavbar({ NavbarId: e }));
let NavbarItems = NavbarData?.filter((a) => a.ComponentId === e);
dispatch(
changePreviewComponents({
BookingNavbar: [
NavbarItems[0]?.ComponentName,
NavbarItems[0]?.ComponentOptionsDetails,
],
})
);
setNavBarCheckList(NavbarItems);
// Find the object with OptionName equal to "Search" and extract OptionId
const searchOption = NavbarItems[0]?.ComponentOptionsDetails?.find(
(option) => option.OptionName === 'Search'
);
if (searchOption) {
setSelectedNavCheckList([{ OptionId: searchOption.OptionId }]);
setSelectedNavCheckValues((prevState) => {
// If prevState is undefined, initialize it as an empty array
const newState = Array.isArray(prevState) ? prevState : [];
return [...newState, searchOption.OptionId];
});
}
//