diff --git a/src/Pages/Preference/PreferenceList.jsx b/src/Pages/Preference/PreferenceList.jsx index 130e3ab..7c039d0 100644 --- a/src/Pages/Preference/PreferenceList.jsx +++ b/src/Pages/Preference/PreferenceList.jsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useRef, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { Form, Checkbox, Radio, Divider } from 'antd'; +import { Form, Checkbox, Radio, Divider, InputNumber } from 'antd'; import { ArrowRightOutlined } from '@ant-design/icons'; import FormHeader from '../PageComponents/FormHeader.jsx'; import Buttons from '../../Components/Forms/Buttons.jsx'; @@ -57,68 +57,71 @@ const PreferenceList = () => { const settingsList = tableValue[0]?.SettingDtlDetails ?? preferenceConfigs; const allSettingsMap = {}; - settingsList?.forEach(({ SettingIdName, SettingValue }) => { - allSettingsMap[SettingIdName?.toLowerCase()] = SettingValue; + settingsList?.forEach(({ SettingIdName, SettingValue, SettingCount }) => { + allSettingsMap[SettingIdName?.toLowerCase()] = { value: SettingValue, count: SettingCount }; }); - console.log(allSettingsMap, 'allSettingsMapallSettingsMapallSettingsMap'); + console.log(settingsList, 'settingsList'); const buildInitialValues = () => ({ - dashboard: allSettingsMap['dashboard'] === 'Y', - shortcutkeys: allSettingsMap['shortcutkeys'] === 'Y', - autoreceivestock: allSettingsMap['autoreceivestock'] === 'Y', - decimal: allSettingsMap['decimal'] === 'Y', + dashboard: allSettingsMap['dashboard']?.value === 'Y', + shortcutkeys: allSettingsMap['shortcutkeys']?.value === 'Y', + autoreceivestock: allSettingsMap['autoreceivestock']?.value === 'Y', + decimal: allSettingsMap['decimal']?.value === 'Y', enabledModules: [ - ...(allSettingsMap['dinein'] === 'Y' ? ['dinein'] : []), - ...(allSettingsMap['estimation'] === 'Y' ? ['estimation'] : []), + ...(allSettingsMap['dinein']?.value === 'Y' ? ['dinein'] : []), + ...(allSettingsMap['estimation']?.value === 'Y' ? ['estimation'] : []), ], - searchfocus: allSettingsMap['searchfocus'] === 'Y', - addproductcard: allSettingsMap['addproductcard'] === 'Y', + searchfocus: allSettingsMap['searchfocus']?.value === 'Y', + addproductcard: allSettingsMap['addproductcard']?.value === 'Y', enabledFeatures: [ - ...(allSettingsMap['parking'] === 'Y' ? ['parking'] : []), - ...(allSettingsMap['offer'] === 'Y' ? ['offer'] : []), + ...(allSettingsMap['parking']?.value === 'Y' ? ['parking'] : []), + ...(allSettingsMap['offer']?.value === 'Y' ? ['offer'] : []), ], - stockselection: allSettingsMap['stockselection'] === 'Y', - weightasquantity: allSettingsMap['weightasquantity'] === 'Y', - expiredselection: allSettingsMap['expiredselection'] === 'Y', - 'sales mode': allSettingsMap['sales mode'] === 'Y', - billitemsorder: allSettingsMap['billitemsorder'] === 'Y', - preorderpricechange: allSettingsMap['preorderpricechange'] === 'Y', + stockselection: allSettingsMap['stockselection']?.value === 'Y', + weightasquantity: allSettingsMap['weightasquantity']?.value === 'Y', + expiredselection: allSettingsMap['expiredselection']?.value === 'Y', + 'sales mode': allSettingsMap['sales mode']?.value === 'Y', + billitemsorder: allSettingsMap['billitemsorder']?.value === 'Y', + preorderpricechange: allSettingsMap['preorderpricechange']?.value === 'Y', + quantityrestriction: allSettingsMap['overalllimit']?.value === 'Y' || allSettingsMap['itemwiselimit']?.value === 'Y', + quantityrestrictiontype: allSettingsMap['overalllimit']?.value === 'Y' ? 'overall' : allSettingsMap['itemwiselimit']?.value === 'Y' ? 'itemwise' : 'overall', + maxquantity: allSettingsMap['overalllimit']?.value === 'Y' ? allSettingsMap['overalllimit']?.count || 1 : allSettingsMap['itemwiselimit']?.value === 'Y' ? allSettingsMap['itemwiselimit']?.count || 1 : 1, billOption: ['whatsapp', 'sms', 'email'].some( - (k) => allSettingsMap[k] === 'Y' + (k) => allSettingsMap[k]?.value === 'Y' ) ? 'pdf' : 'print', pdfSendOptions: ['whatsapp', 'email', 'sms'].filter( - (k) => allSettingsMap[k] === 'Y' + (k) => allSettingsMap[k]?.value === 'Y' ), - tokenonly: allSettingsMap['tokenonly'] === 'Y', + tokenonly: allSettingsMap['tokenonly']?.value === 'Y', allproductindividualtoken: - allSettingsMap['allproductindividualtoken'] === 'Y', + allSettingsMap['allproductindividualtoken']?.value === 'Y', printOptions: ['printuom', 'printlogo', 'printgreetings'].filter( - (k) => allSettingsMap[k] === 'Y' + (k) => allSettingsMap[k]?.value === 'Y' ), - mobilea4: allSettingsMap['mobilea4'] === 'Y', - estimateprintheader: allSettingsMap['estimateprintheader'] === 'Y', - scanlayout: allSettingsMap['scanlayout'] === 'Y', - verifyproduct: allSettingsMap['verifyproduct'] === 'Y', - customisedbillnumber: allSettingsMap['customisedbillnumber'] === 'Y', - upiqr: allSettingsMap['upiqr'] === 'Y', - lowstockreport: allSettingsMap['lowstockreport'] === 'Y', - weeklysalesreport: allSettingsMap['weeklysalesreport'] === 'Y', - notificationblink: allSettingsMap['notificationblink'] === 'Y', - onlineindivdualslots: allSettingsMap['onlineindivdualslots'] === 'Y', - editbill: allSettingsMap['editbill'] === 'Y', + mobilea4: allSettingsMap['mobilea4']?.value === 'Y', + estimateprintheader: allSettingsMap['estimateprintheader']?.value === 'Y', + scanlayout: allSettingsMap['scanlayout']?.value === 'Y', + verifyproduct: allSettingsMap['verifyproduct']?.value === 'Y', + customisedbillnumber: allSettingsMap['customisedbillnumber']?.value === 'Y', + upiqr: allSettingsMap['upiqr']?.value === 'Y', + lowstockreport: allSettingsMap['lowstockreport']?.value === 'Y', + weeklysalesreport: allSettingsMap['weeklysalesreport']?.value === 'Y', + notificationblink: allSettingsMap['notificationblink']?.value === 'Y', + onlineindivdualslots: allSettingsMap['onlineindivdualslots']?.value === 'Y', + editbill: allSettingsMap['editbill']?.value === 'Y', notification: [ - ...(allSettingsMap['onbilltime'] === 'Y' ? ['onbilltime'] : []), - ...(allSettingsMap['1daybefore'] === 'Y' ? ['1daybefore'] : []), - ...(allSettingsMap['1hourbefore'] === 'Y' ? ['1hourbefore'] : []), + ...(allSettingsMap['onbilltime']?.value === 'Y' ? ['onbilltime'] : []), + ...(allSettingsMap['1daybefore']?.value === 'Y' ? ['1daybefore'] : []), + ...(allSettingsMap['1hourbefore']?.value === 'Y' ? ['1hourbefore'] : []), ], BookingOptionsandmethod: [ - ...(allSettingsMap['allow individual booking'] === 'Y' + ...(allSettingsMap['allow individual booking']?.value === 'Y' ? ['allow individual booking'] : []), - ...(allSettingsMap['single booking only'] === 'Y' + ...(allSettingsMap['single booking only']?.value === 'Y' ? ['single booking only'] : []), ], @@ -310,6 +313,8 @@ const PreferenceList = () => { weeklysalesreport: values.weeklysalesreport, notificationblink: values.notificationblink, editbill: values.editbill, + overalllimit: values.quantityrestriction && values.quantityrestrictiontype === 'overall', + itemwiselimit: values.quantityrestriction && values.quantityrestrictiontype === 'itemwise', }; const arrayValues = { @@ -340,6 +345,7 @@ const PreferenceList = () => { SettingId: setting.SettingId, Comments: setting.Comments || 'Enter Comment', SettingValue: isChecked ? 'Y' : 'N', + SettingCount: ((key === 'overalllimit' || key === 'itemwiselimit') && isChecked) ? parseFloat(values.maxquantity) || null : null }; }); @@ -482,25 +488,25 @@ const PreferenceList = () => { {(allSettingsMap['onlineindividualslots'] !== undefined || allSettingsMap['allow individual booking'] !== undefined || allSettingsMap['single booking only'] !== undefined) && ( -