ordering-ui-admin-external 1.17.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_bundles/{ordering-ui-admin.6c1919d6b0356a2f522f.js → ordering-ui-admin.661a37246ac77dcc4edf.js} +2 -2
- package/_modules/components/Delivery/DeliveryUsersListing/index.js +4 -2
- package/_modules/components/Delivery/DriversGroupLogistics/index.js +1 -1
- package/_modules/components/Delivery/DriversGroupLogs/index.js +1 -0
- package/_modules/components/Delivery/UsersList/index.js +47 -51
- package/_modules/components/Delivery/UsersList/styles.js +6 -4
- package/_modules/components/Home/HomePage/index.js +7 -1
- package/_modules/components/Login/LoginForm/index.js +7 -1
- package/_modules/components/Marketing/EnterprisePromotionListing/index.js +1 -1
- package/_modules/components/Messages/MessagesListing/index.js +1 -1
- package/_modules/components/MyProducts/AdvancedSettings/ButtonShadow.js +98 -0
- package/_modules/components/MyProducts/AdvancedSettings/FontStyleGroup.js +28 -7
- package/_modules/components/MyProducts/AdvancedSettings/HideCheckBox.js +47 -0
- package/_modules/components/MyProducts/AdvancedSettings/ImageBox.js +12 -3
- package/_modules/components/MyProducts/AdvancedSettings/SettingComponent.js +15 -15
- package/_modules/components/MyProducts/AdvancedSettings/index.js +102 -117
- package/_modules/components/MyProducts/AppResources/index.js +132 -0
- package/_modules/components/MyProducts/OrderingWebsite/index.js +47 -2
- package/_modules/components/MyProducts/OrderingWebsite/styles.js +13 -3
- package/_modules/components/OrderingProducts/SiteTheme/index.js +13 -9
- package/_modules/components/Orders/DeliveriesManager/index.js +1 -1
- package/_modules/components/Orders/Messages/index.js +25 -94
- package/_modules/components/Orders/OrderBill/index.js +3 -3
- package/_modules/components/Orders/OrderNotification/index.js +4 -2
- package/_modules/components/Orders/OrdersManager/index.js +3 -1
- package/_modules/components/SidebarMenu/index.js +34 -33
- package/_modules/components/Stores/BusinessAdd/DeliveryZone/index.js +1 -1
- package/_modules/components/Stores/BusinessDeliveryZoneInformation/index.js +1 -1
- package/_modules/components/Stores/BusinessDetails/index.js +27 -8
- package/_modules/components/Stores/BusinessLocation/index.js +8 -7
- package/_modules/components/Stores/BusinessPlace/index.js +127 -0
- package/_modules/components/Stores/BusinessPlace/styles.js +55 -0
- package/_modules/components/Stores/BusinessPlaceGroup/index.js +258 -0
- package/_modules/components/Stores/BusinessPlaceGroup/styles.js +102 -0
- package/_modules/components/Stores/BusinessProductList/index.js +3 -3
- package/_modules/components/Stores/BusinessProductsListing/index.js +2 -1
- package/_modules/components/Stores/BusinessSummary/index.js +12 -3
- package/_modules/components/Stores/ProductStep/index.js +15 -3
- package/_modules/components/Stores/SpoonityApiKey/index.js +97 -0
- package/_modules/components/Stores/SpoonityApiKey/styles.js +47 -0
- package/_modules/components/Stores/UploadMenuGuide/index.js +8 -0
- package/_modules/components/Users/CustomerPointsWallet/index.js +126 -9
- package/_modules/components/Users/CustomerPointsWallet/styles.js +8 -4
- package/package.json +2 -2
- package/src/components/Delivery/DeliveryUsersListing/index.js +3 -1
- package/src/components/Delivery/DriversGroupLogistics/index.js +1 -1
- package/src/components/Delivery/DriversGroupLogs/index.js +2 -0
- package/src/components/Delivery/UsersList/index.js +79 -61
- package/src/components/Delivery/UsersList/styles.js +4 -12
- package/src/components/Home/HomePage/index.js +2 -2
- package/src/components/Login/LoginForm/index.js +4 -1
- package/src/components/Marketing/EnterprisePromotionListing/index.js +1 -1
- package/src/components/Messages/MessagesListing/index.js +1 -1
- package/src/components/MyProducts/AdvancedSettings/ButtonShadow.js +102 -0
- package/src/components/MyProducts/AdvancedSettings/FontStyleGroup.js +23 -5
- package/src/components/MyProducts/AdvancedSettings/HideCheckBox.js +33 -0
- package/src/components/MyProducts/AdvancedSettings/ImageBox.js +10 -3
- package/src/components/MyProducts/AdvancedSettings/SettingComponent.js +10 -15
- package/src/components/MyProducts/AdvancedSettings/index.js +119 -149
- package/src/components/MyProducts/AppResources/index.js +167 -0
- package/src/components/MyProducts/OrderingWebsite/index.js +66 -2
- package/src/components/MyProducts/OrderingWebsite/styles.js +37 -0
- package/src/components/OrderingProducts/SiteTheme/index.js +7 -3
- package/src/components/Orders/DeliveriesManager/index.js +1 -1
- package/src/components/Orders/Messages/index.js +56 -216
- package/src/components/Orders/OrderBill/index.js +6 -2
- package/src/components/Orders/OrderNotification/index.js +6 -2
- package/src/components/Orders/OrdersManager/index.js +1 -1
- package/src/components/SidebarMenu/index.js +8 -8
- package/src/components/Stores/BusinessAdd/DeliveryZone/index.js +1 -1
- package/src/components/Stores/BusinessDeliveryZoneInformation/index.js +1 -1
- package/src/components/Stores/BusinessDetails/index.js +24 -1
- package/src/components/Stores/BusinessLocation/index.js +2 -1
- package/src/components/Stores/BusinessPlace/index.js +137 -0
- package/src/components/Stores/BusinessPlace/styles.js +132 -0
- package/src/components/Stores/BusinessPlaceGroup/index.js +272 -0
- package/src/components/Stores/BusinessPlaceGroup/styles.js +248 -0
- package/src/components/Stores/BusinessProductList/index.js +9 -1
- package/src/components/Stores/BusinessProductsListing/index.js +1 -0
- package/src/components/Stores/BusinessSummary/index.js +16 -5
- package/src/components/Stores/ProductStep/index.js +19 -2
- package/src/components/Stores/SpoonityApiKey/index.js +87 -0
- package/src/components/Stores/SpoonityApiKey/styles.js +68 -0
- package/src/components/Stores/UploadMenuGuide/index.js +10 -1
- package/src/components/Users/CustomerPointsWallet/index.js +130 -2
- package/src/components/Users/CustomerPointsWallet/styles.js +40 -1
- /package/_bundles/{ordering-ui-admin.6c1919d6b0356a2f522f.js.LICENSE.txt → ordering-ui-admin.661a37246ac77dcc4edf.js.LICENSE.txt} +0 -0
|
@@ -18,6 +18,8 @@ import { BusinessNotifications } from '../BusinessNotifications'
|
|
|
18
18
|
import { BusinessOrderingChannels } from '../BusinessOrderingChannels'
|
|
19
19
|
import { BusinessFrontLayout } from '../BusinessFrontLayout'
|
|
20
20
|
// import { BusinessPublishing } from '../BusinessPublishing'
|
|
21
|
+
import { BusinessPlaceGroupList } from '../BusinessPlaceGroupList'
|
|
22
|
+
import { SpoonityApiKey } from '../SpoonityApiKey'
|
|
21
23
|
|
|
22
24
|
import { MoreSidebarLayout, Personalization, Alert } from '../../Shared'
|
|
23
25
|
|
|
@@ -46,7 +48,9 @@ export const BusinessDetailsUI = (props) => {
|
|
|
46
48
|
handleDuplicateBusiness,
|
|
47
49
|
handleDeleteBusiness,
|
|
48
50
|
actionStatus,
|
|
49
|
-
handleUpdatePreorderConfigs
|
|
51
|
+
handleUpdatePreorderConfigs,
|
|
52
|
+
handleUpdateSpoonityKey,
|
|
53
|
+
spoonityKeyState
|
|
50
54
|
} = props
|
|
51
55
|
|
|
52
56
|
const history = useHistory()
|
|
@@ -58,6 +62,7 @@ export const BusinessDetailsUI = (props) => {
|
|
|
58
62
|
const [extraOpen, setExtraOpen] = useState(false)
|
|
59
63
|
const [isExtendExtraOpen, setIsExtendExtraOpen] = useState(false)
|
|
60
64
|
const [alertState, setAlertState] = useState({ open: false, content: [] })
|
|
65
|
+
const spoonityConfig = businessState?.business?.configs?.find(config => config.key === 'spoonity_integration_api_key')
|
|
61
66
|
|
|
62
67
|
const isAdmin = user?.level === 0
|
|
63
68
|
|
|
@@ -178,6 +183,7 @@ export const BusinessDetailsUI = (props) => {
|
|
|
178
183
|
handleDuplicateBusiness={handleDuplicateBusiness}
|
|
179
184
|
handleDeleteBusiness={handleDeleteBusiness}
|
|
180
185
|
extraOpen={extraOpen}
|
|
186
|
+
spoonityConfig={spoonityConfig}
|
|
181
187
|
/>
|
|
182
188
|
)}
|
|
183
189
|
{extraOpen && (
|
|
@@ -320,6 +326,23 @@ export const BusinessDetailsUI = (props) => {
|
|
|
320
326
|
handleSuccessUpdate={handleUpdateBusinessState}
|
|
321
327
|
/>
|
|
322
328
|
)}
|
|
329
|
+
{selectedItem === 'places' && (
|
|
330
|
+
<BusinessPlaceGroupList
|
|
331
|
+
business={businessState?.business}
|
|
332
|
+
handleSuccessUpdate={handleUpdateBusinessState}
|
|
333
|
+
setIsExtendExtraOpen={setIsExtendExtraOpen}
|
|
334
|
+
/>
|
|
335
|
+
)}
|
|
336
|
+
{selectedItem === 'spoonity_key' && (
|
|
337
|
+
<SpoonityApiKey
|
|
338
|
+
business={businessState?.business}
|
|
339
|
+
handleSuccessUpdate={handleUpdateBusinessState}
|
|
340
|
+
handleUpdateBusinessClick={handleUpdateBusinessClick}
|
|
341
|
+
spoonityConfig={spoonityConfig}
|
|
342
|
+
handleUpdateSpoonityKey={handleUpdateSpoonityKey}
|
|
343
|
+
spoonityKeyState={spoonityKeyState}
|
|
344
|
+
/>
|
|
345
|
+
)}
|
|
323
346
|
</MoreSidebarLayout>
|
|
324
347
|
)}
|
|
325
348
|
|
|
@@ -57,7 +57,8 @@ export const BusinessLocation = (props) => {
|
|
|
57
57
|
const getTimeZone = async (address) => {
|
|
58
58
|
const date = new Date()
|
|
59
59
|
const timestamp = Math.floor(date.getTime() / 1000)
|
|
60
|
-
const
|
|
60
|
+
const timezoneApiKey = googleMapsApiKey === 'AIzaSyBvsSkMYPSDSkdk7YFrSf5FoGonIzr6fJ0' ? 'AIzaSyCYPCOfiTo9jxuxLWnWTup6mmICPxfLegI' : googleMapsApiKey
|
|
61
|
+
const url = `https://maps.googleapis.com/maps/api/timezone/json?location=${address?.location?.lat},${address?.location?.lng}×tamp=${timestamp}&key=${timezoneApiKey}`
|
|
61
62
|
const response = await fetch(url, {
|
|
62
63
|
method: 'GET'
|
|
63
64
|
})
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react'
|
|
2
|
+
import { useLanguage, BusinessPlace as BusinessPlaceController } from 'ordering-components-admin-external'
|
|
3
|
+
import { DropdownButton, Dropdown } from 'react-bootstrap'
|
|
4
|
+
import { XLg, ThreeDots } from 'react-bootstrap-icons'
|
|
5
|
+
import { useTheme } from 'styled-components'
|
|
6
|
+
import { Button, IconButton, Input } from '../../../styles'
|
|
7
|
+
import { useForm } from 'react-hook-form'
|
|
8
|
+
import { Alert } from '../../Shared'
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
Container,
|
|
12
|
+
Header,
|
|
13
|
+
ActionBlock,
|
|
14
|
+
ActionSelectorWrapper,
|
|
15
|
+
Content,
|
|
16
|
+
ButtonWrapper,
|
|
17
|
+
HideSubmitBtn
|
|
18
|
+
} from './styles'
|
|
19
|
+
|
|
20
|
+
export const BusinessPlaceUI = (props) => {
|
|
21
|
+
const {
|
|
22
|
+
onClose,
|
|
23
|
+
place,
|
|
24
|
+
formState,
|
|
25
|
+
handleChangeInput,
|
|
26
|
+
handleAddPlace,
|
|
27
|
+
handleUpdatePlace,
|
|
28
|
+
handleDeletePlace
|
|
29
|
+
} = props
|
|
30
|
+
|
|
31
|
+
const theme = useTheme()
|
|
32
|
+
const [, t] = useLanguage()
|
|
33
|
+
const formMethods = useForm()
|
|
34
|
+
|
|
35
|
+
const [alertState, setAlertState] = useState({ open: false, content: [] })
|
|
36
|
+
|
|
37
|
+
const buttonRef = useRef(null)
|
|
38
|
+
|
|
39
|
+
const closeAlert = () => {
|
|
40
|
+
setAlertState({
|
|
41
|
+
open: false,
|
|
42
|
+
content: []
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const onSubmit = () => {
|
|
47
|
+
if (place) handleUpdatePlace()
|
|
48
|
+
else handleAddPlace()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (Object.keys(formMethods.errors).length > 0) {
|
|
53
|
+
setAlertState({
|
|
54
|
+
open: true,
|
|
55
|
+
content: Object.values(formMethods.errors).map(error => error.message)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
}, [formMethods.errors])
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<>
|
|
62
|
+
<Container>
|
|
63
|
+
<Header>
|
|
64
|
+
<h1>{place ? place?.name : t('NEW_OPTION', 'New option')}</h1>
|
|
65
|
+
<ActionBlock>
|
|
66
|
+
{place && (
|
|
67
|
+
<ActionSelectorWrapper>
|
|
68
|
+
<DropdownButton
|
|
69
|
+
className='product_actions'
|
|
70
|
+
menuAlign={theme?.rtl ? 'left' : 'right'}
|
|
71
|
+
title={<ThreeDots />}
|
|
72
|
+
id={theme?.rtl ? 'dropdown-menu-align-left' : 'dropdown-menu-align-right'}
|
|
73
|
+
>
|
|
74
|
+
<Dropdown.Item
|
|
75
|
+
onClick={() => handleDeletePlace()}
|
|
76
|
+
>
|
|
77
|
+
{t('DELETE', 'Delete')}
|
|
78
|
+
</Dropdown.Item>
|
|
79
|
+
</DropdownButton>
|
|
80
|
+
</ActionSelectorWrapper>
|
|
81
|
+
)}
|
|
82
|
+
<IconButton
|
|
83
|
+
color='black'
|
|
84
|
+
onClick={() => onClose()}
|
|
85
|
+
>
|
|
86
|
+
<XLg />
|
|
87
|
+
</IconButton>
|
|
88
|
+
</ActionBlock>
|
|
89
|
+
</Header>
|
|
90
|
+
<Content onSubmit={formMethods.handleSubmit(onSubmit)}>
|
|
91
|
+
<label>{t('NAME', 'Name')}</label>
|
|
92
|
+
<Input
|
|
93
|
+
placeholder={t('NAME', 'Name')}
|
|
94
|
+
name='name'
|
|
95
|
+
autoComplete='off'
|
|
96
|
+
onChange={handleChangeInput}
|
|
97
|
+
value={formState?.changes?.name ?? place?.name ?? ''}
|
|
98
|
+
ref={formMethods.register({
|
|
99
|
+
required: t(
|
|
100
|
+
'VALIDATION_ERROR_REQUIRED',
|
|
101
|
+
'Name is required'
|
|
102
|
+
).replace('_attribute_', t('NAME', 'Name'))
|
|
103
|
+
})}
|
|
104
|
+
/>
|
|
105
|
+
<HideSubmitBtn type='submit' ref={buttonRef} />
|
|
106
|
+
</Content>
|
|
107
|
+
<ButtonWrapper>
|
|
108
|
+
<Button
|
|
109
|
+
color='primary'
|
|
110
|
+
borderRadius='8px'
|
|
111
|
+
disabled={Object.keys(formState?.changes).length === 0}
|
|
112
|
+
onClick={() => buttonRef.current.click()}
|
|
113
|
+
>
|
|
114
|
+
{place ? t('SAVE', 'Save') : t('ADD', 'Add')}
|
|
115
|
+
</Button>
|
|
116
|
+
</ButtonWrapper>
|
|
117
|
+
</Container>
|
|
118
|
+
<Alert
|
|
119
|
+
title={t('PLACES', 'Places')}
|
|
120
|
+
content={alertState.content}
|
|
121
|
+
acceptText={t('ACCEPT', 'Accept')}
|
|
122
|
+
open={alertState.open}
|
|
123
|
+
onClose={() => closeAlert()}
|
|
124
|
+
onAccept={() => closeAlert()}
|
|
125
|
+
closeOnBackdrop={false}
|
|
126
|
+
/>
|
|
127
|
+
</>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const BusinessPlace = (props) => {
|
|
132
|
+
const businessPlaceProps = {
|
|
133
|
+
...props,
|
|
134
|
+
UIComponent: BusinessPlaceUI
|
|
135
|
+
}
|
|
136
|
+
return <BusinessPlaceController {...businessPlaceProps} />
|
|
137
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components'
|
|
2
|
+
import { darken } from 'polished'
|
|
3
|
+
|
|
4
|
+
export const Container = styled.div`
|
|
5
|
+
transition: 0.3s;
|
|
6
|
+
height: 100%;
|
|
7
|
+
|
|
8
|
+
> button {
|
|
9
|
+
height: 42px;
|
|
10
|
+
width: 100%;
|
|
11
|
+
margin-top: 20px;
|
|
12
|
+
}
|
|
13
|
+
`
|
|
14
|
+
|
|
15
|
+
export const Header = styled.div`
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: space-between;
|
|
19
|
+
position: relative;
|
|
20
|
+
h1 {
|
|
21
|
+
font-size: 20px;
|
|
22
|
+
font-weight: 700;
|
|
23
|
+
margin: 5px 0;
|
|
24
|
+
color: ${props => props.theme.colors.headingColor};
|
|
25
|
+
${props => props.theme?.rtl ? css`
|
|
26
|
+
margin-left: 80px;
|
|
27
|
+
` : css`
|
|
28
|
+
margin-right: 80px;
|
|
29
|
+
`}
|
|
30
|
+
}
|
|
31
|
+
`
|
|
32
|
+
|
|
33
|
+
export const ActionBlock = styled.div`
|
|
34
|
+
background: ${props => props.theme.colors?.backgroundPage || '#FFF'};
|
|
35
|
+
position: absolute;
|
|
36
|
+
z-index: 1000;
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
> button {
|
|
40
|
+
display: none;
|
|
41
|
+
}
|
|
42
|
+
${props => props.theme?.rtl ? css`
|
|
43
|
+
left: 0px;
|
|
44
|
+
` : css`
|
|
45
|
+
right: 0px;
|
|
46
|
+
`}
|
|
47
|
+
@media (min-width: 1000px) {
|
|
48
|
+
> button {
|
|
49
|
+
display: block;
|
|
50
|
+
${props => props.theme?.rtl ? css`
|
|
51
|
+
margin-right: 10px;
|
|
52
|
+
` : css`
|
|
53
|
+
margin-left: 10px;
|
|
54
|
+
`}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
`
|
|
58
|
+
|
|
59
|
+
export const ActionSelectorWrapper = styled.div`
|
|
60
|
+
button {
|
|
61
|
+
display: flex;
|
|
62
|
+
background: transparent !important;
|
|
63
|
+
border: none;
|
|
64
|
+
padding: 5px;
|
|
65
|
+
border-radius: 8px;
|
|
66
|
+
&:active,
|
|
67
|
+
&:focus {
|
|
68
|
+
border-color: unset !important;
|
|
69
|
+
box-shadow: none !important;
|
|
70
|
+
}
|
|
71
|
+
svg {
|
|
72
|
+
color: ${props => props.theme.colors.headingColor};
|
|
73
|
+
font-size: 20px;
|
|
74
|
+
}
|
|
75
|
+
&:after {
|
|
76
|
+
display: none;
|
|
77
|
+
}
|
|
78
|
+
&:hover {
|
|
79
|
+
background: ${props => darken(0.04, props.theme.colors.secundary)} !important;
|
|
80
|
+
}
|
|
81
|
+
&:active {
|
|
82
|
+
background: ${props => darken(0.1, props.theme.colors.secundaryDarkContrast)} !important;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
.show {
|
|
86
|
+
>div {
|
|
87
|
+
border: 1px solid ${props => props.theme.colors.borderColor};
|
|
88
|
+
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.12);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
> div {
|
|
92
|
+
> div {
|
|
93
|
+
border-radius: 8px;
|
|
94
|
+
.dropdown-item {
|
|
95
|
+
font-size: 12px;
|
|
96
|
+
color: ${props => props.theme.colors.headingColor};
|
|
97
|
+
padding: 7px 20px;
|
|
98
|
+
&:active {
|
|
99
|
+
background: ${props => darken(0.1, props.theme.colors.secundary)} !important;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
.dropdown-item:last-child {
|
|
103
|
+
color: ${props => props.theme.colors.danger};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`
|
|
108
|
+
|
|
109
|
+
export const Content = styled.form`
|
|
110
|
+
margin-top: 30px;
|
|
111
|
+
label {
|
|
112
|
+
font-weight: 400;
|
|
113
|
+
font-size: 14px;
|
|
114
|
+
margin-bottom: 10px;
|
|
115
|
+
}
|
|
116
|
+
input {
|
|
117
|
+
height: 44px;
|
|
118
|
+
width: 100%;
|
|
119
|
+
}
|
|
120
|
+
`
|
|
121
|
+
|
|
122
|
+
export const ButtonWrapper = styled.div`
|
|
123
|
+
position: sticky;
|
|
124
|
+
top: 100%;
|
|
125
|
+
button {
|
|
126
|
+
height: 44px;
|
|
127
|
+
}
|
|
128
|
+
`
|
|
129
|
+
|
|
130
|
+
export const HideSubmitBtn = styled.button`
|
|
131
|
+
display: none;
|
|
132
|
+
`
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react'
|
|
2
|
+
import { useLanguage, BusinessPlaceGroup as BusinessPlaceGroupController } from 'ordering-components-admin-external'
|
|
3
|
+
import { DropdownButton, Dropdown } from 'react-bootstrap'
|
|
4
|
+
import { useTheme } from 'styled-components'
|
|
5
|
+
import { useWindowSize } from '../../../hooks/useWindowSize'
|
|
6
|
+
import { Button, IconButton, Input } from '../../../styles'
|
|
7
|
+
import { useForm } from 'react-hook-form'
|
|
8
|
+
import { Alert, Modal } from '../../Shared'
|
|
9
|
+
import Skeleton from 'react-loading-skeleton'
|
|
10
|
+
import { BusinessPlace } from '../BusinessPlace'
|
|
11
|
+
import { ChevronRight, CheckSquareFill, Square, XLg, ThreeDots } from 'react-bootstrap-icons'
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
Container,
|
|
15
|
+
Header,
|
|
16
|
+
ActionBlock,
|
|
17
|
+
ActionSelectorWrapper,
|
|
18
|
+
Content,
|
|
19
|
+
ButtonWrapper,
|
|
20
|
+
HideSubmitBtn,
|
|
21
|
+
OptionList,
|
|
22
|
+
AddBtn,
|
|
23
|
+
PlaceItemContainer,
|
|
24
|
+
CheckWrapper,
|
|
25
|
+
TableHead
|
|
26
|
+
} from './styles'
|
|
27
|
+
|
|
28
|
+
export const BusinessPlaceGroupUI = (props) => {
|
|
29
|
+
const {
|
|
30
|
+
open,
|
|
31
|
+
onClose,
|
|
32
|
+
placeGroup,
|
|
33
|
+
formState,
|
|
34
|
+
handleChangeInput,
|
|
35
|
+
handleAddPlaceGroup,
|
|
36
|
+
handleUpdatePlaceGroup,
|
|
37
|
+
handleDeletePlaceGroup,
|
|
38
|
+
placeList,
|
|
39
|
+
handleSuccessDeletePlace,
|
|
40
|
+
handleSuccessAddPlace,
|
|
41
|
+
handleSuccessUpdatePlace,
|
|
42
|
+
handleChangePlaceEnabled,
|
|
43
|
+
businessId,
|
|
44
|
+
handleMultiPlaceChangeEnabled,
|
|
45
|
+
getMultiPlaceCheckStatus
|
|
46
|
+
} = props
|
|
47
|
+
|
|
48
|
+
const theme = useTheme()
|
|
49
|
+
const [, t] = useLanguage()
|
|
50
|
+
const { width } = useWindowSize()
|
|
51
|
+
const formMethods = useForm()
|
|
52
|
+
|
|
53
|
+
const [isMenuOpen, setIsMenuOpen] = useState(false)
|
|
54
|
+
const [alertState, setAlertState] = useState({ open: false, content: [] })
|
|
55
|
+
const [selectedPlace, setSelectedPlace] = useState(null)
|
|
56
|
+
const [openModal, setOpenModal] = useState(false)
|
|
57
|
+
|
|
58
|
+
const buttonRef = useRef(null)
|
|
59
|
+
|
|
60
|
+
const actionSidebar = (value) => {
|
|
61
|
+
if (!value) {
|
|
62
|
+
props.onClose()
|
|
63
|
+
}
|
|
64
|
+
setIsMenuOpen(value)
|
|
65
|
+
document.getElementById('business_place').style.width = value
|
|
66
|
+
? width > 1000 ? '500px' : '100%'
|
|
67
|
+
: '0'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const handleOpenModal = (place) => {
|
|
71
|
+
setSelectedPlace(place)
|
|
72
|
+
setOpenModal(true)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const closeAlert = () => {
|
|
76
|
+
setAlertState({
|
|
77
|
+
open: false,
|
|
78
|
+
content: []
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const onSubmit = () => {
|
|
83
|
+
if (placeGroup) handleUpdatePlaceGroup()
|
|
84
|
+
else handleAddPlaceGroup()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const handleCloseModal = () => {
|
|
88
|
+
setOpenModal(false)
|
|
89
|
+
setSelectedPlace(null)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (isMenuOpen) {
|
|
94
|
+
if (width < 1000) {
|
|
95
|
+
document.getElementById('business_place').style.width = '100%'
|
|
96
|
+
} else {
|
|
97
|
+
document.getElementById('business_place').style.width = '500px'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [width])
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!open) return
|
|
104
|
+
actionSidebar(true)
|
|
105
|
+
}, [open])
|
|
106
|
+
|
|
107
|
+
const handlePlaceClick = (e, place) => {
|
|
108
|
+
if (e.target.closest('.check-box')) return
|
|
109
|
+
handleOpenModal(place)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const handleCheckBoxChange = (place) => {
|
|
113
|
+
handleChangePlaceEnabled(place?.id, { enabled: !place?.enabled })
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const handleUpdateSelectedPlace = (placeGroup) => {
|
|
117
|
+
setSelectedPlace(placeGroup)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (Object.keys(formMethods.errors).length > 0) {
|
|
122
|
+
setAlertState({
|
|
123
|
+
open: true,
|
|
124
|
+
content: Object.values(formMethods.errors).map(error => error.message)
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
}, [formMethods.errors])
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<>
|
|
131
|
+
<Container id='business_place'>
|
|
132
|
+
<Header>
|
|
133
|
+
<h1>{placeGroup ? placeGroup?.name : t('NEW_PLACE', 'New place')}</h1>
|
|
134
|
+
<ActionBlock>
|
|
135
|
+
{placeGroup && (
|
|
136
|
+
<ActionSelectorWrapper>
|
|
137
|
+
<DropdownButton
|
|
138
|
+
className='product_actions'
|
|
139
|
+
menuAlign={theme?.rtl ? 'left' : 'right'}
|
|
140
|
+
title={<ThreeDots />}
|
|
141
|
+
id={theme?.rtl ? 'dropdown-menu-align-left' : 'dropdown-menu-align-right'}
|
|
142
|
+
>
|
|
143
|
+
<Dropdown.Item
|
|
144
|
+
onClick={() => handleDeletePlaceGroup()}
|
|
145
|
+
>
|
|
146
|
+
{t('DELETE', 'Delete')}
|
|
147
|
+
</Dropdown.Item>
|
|
148
|
+
</DropdownButton>
|
|
149
|
+
</ActionSelectorWrapper>
|
|
150
|
+
)}
|
|
151
|
+
<IconButton
|
|
152
|
+
color='black'
|
|
153
|
+
onClick={() => onClose()}
|
|
154
|
+
>
|
|
155
|
+
<XLg />
|
|
156
|
+
</IconButton>
|
|
157
|
+
</ActionBlock>
|
|
158
|
+
</Header>
|
|
159
|
+
<Content onSubmit={formMethods.handleSubmit(onSubmit)}>
|
|
160
|
+
<label>{t('NAME', 'Name')}</label>
|
|
161
|
+
<Input
|
|
162
|
+
placeholder={t('NAME', 'Name')}
|
|
163
|
+
name='name'
|
|
164
|
+
autoComplete='off'
|
|
165
|
+
onChange={handleChangeInput}
|
|
166
|
+
value={formState?.changes?.name ?? placeGroup?.name ?? ''}
|
|
167
|
+
ref={formMethods.register({
|
|
168
|
+
required: t(
|
|
169
|
+
'VALIDATION_ERROR_REQUIRED',
|
|
170
|
+
'Name is required'
|
|
171
|
+
).replace('_attribute_', t('NAME', 'Name'))
|
|
172
|
+
})}
|
|
173
|
+
/>
|
|
174
|
+
<HideSubmitBtn type='submit' ref={buttonRef} />
|
|
175
|
+
</Content>
|
|
176
|
+
{placeGroup && placeList?.loading && (
|
|
177
|
+
<OptionList>
|
|
178
|
+
{
|
|
179
|
+
[...Array(5).keys()].map(i => (
|
|
180
|
+
<PlaceItemContainer key={i}>
|
|
181
|
+
<CheckWrapper>
|
|
182
|
+
<Skeleton width={16} height={16} />
|
|
183
|
+
<label>
|
|
184
|
+
<Skeleton width={100} />
|
|
185
|
+
</label>
|
|
186
|
+
</CheckWrapper>
|
|
187
|
+
<Skeleton width={16} height={16} />
|
|
188
|
+
</PlaceItemContainer>
|
|
189
|
+
))
|
|
190
|
+
}
|
|
191
|
+
</OptionList>
|
|
192
|
+
)}
|
|
193
|
+
{placeGroup && !placeList?.loading && (
|
|
194
|
+
<OptionList>
|
|
195
|
+
{placeList?.places?.length > 0 && (
|
|
196
|
+
<TableHead>
|
|
197
|
+
<CheckWrapper>
|
|
198
|
+
<span className='check-box' onClick={() => handleMultiPlaceChangeEnabled()}>
|
|
199
|
+
{getMultiPlaceCheckStatus() ? <CheckSquareFill className='active' /> : <Square />}
|
|
200
|
+
</span>
|
|
201
|
+
<label>{t('OPTIONS', 'Options')}</label>
|
|
202
|
+
</CheckWrapper>
|
|
203
|
+
</TableHead>
|
|
204
|
+
)}
|
|
205
|
+
{placeList?.places?.map((place, i) => (
|
|
206
|
+
<PlaceItemContainer
|
|
207
|
+
key={i}
|
|
208
|
+
active={selectedPlace?.id === place?.id}
|
|
209
|
+
onClick={(e) => handlePlaceClick(e, place)}
|
|
210
|
+
>
|
|
211
|
+
<CheckWrapper>
|
|
212
|
+
<span className='check-box' onClick={() => handleCheckBoxChange(place)}>
|
|
213
|
+
{place?.enabled ? <CheckSquareFill className='active' /> : <Square />}
|
|
214
|
+
</span>
|
|
215
|
+
<label>{place?.name}</label>
|
|
216
|
+
</CheckWrapper>
|
|
217
|
+
<ChevronRight />
|
|
218
|
+
</PlaceItemContainer>
|
|
219
|
+
))}
|
|
220
|
+
</OptionList>
|
|
221
|
+
)}
|
|
222
|
+
{placeGroup && <AddBtn onClick={() => handleOpenModal(null)}>{t('ADD_OPTION', 'Add option')}</AddBtn>}
|
|
223
|
+
<ButtonWrapper>
|
|
224
|
+
<Button
|
|
225
|
+
color='primary'
|
|
226
|
+
borderRadius='8px'
|
|
227
|
+
disabled={Object.keys(formState?.changes).length === 0}
|
|
228
|
+
onClick={() => buttonRef.current.click()}
|
|
229
|
+
>
|
|
230
|
+
{placeGroup ? t('SAVE', 'Save') : t('ADD', 'Add')}
|
|
231
|
+
</Button>
|
|
232
|
+
</ButtonWrapper>
|
|
233
|
+
</Container>
|
|
234
|
+
<Alert
|
|
235
|
+
title={t('PLACES', 'Places')}
|
|
236
|
+
content={alertState.content}
|
|
237
|
+
acceptText={t('ACCEPT', 'Accept')}
|
|
238
|
+
open={alertState.open}
|
|
239
|
+
onClose={() => closeAlert()}
|
|
240
|
+
onAccept={() => closeAlert()}
|
|
241
|
+
closeOnBackdrop={false}
|
|
242
|
+
/>
|
|
243
|
+
<Modal
|
|
244
|
+
width='700px'
|
|
245
|
+
height='80vh'
|
|
246
|
+
padding='30px'
|
|
247
|
+
open={openModal}
|
|
248
|
+
onClose={() => handleCloseModal()}
|
|
249
|
+
hideCloseDefault
|
|
250
|
+
>
|
|
251
|
+
<BusinessPlace
|
|
252
|
+
businessId={businessId}
|
|
253
|
+
place={selectedPlace}
|
|
254
|
+
placeGroup={placeGroup}
|
|
255
|
+
handleUpdateSelectedPlace={handleUpdateSelectedPlace}
|
|
256
|
+
handleSuccessUpdatePlace={handleSuccessUpdatePlace}
|
|
257
|
+
handleSuccessAddPlace={handleSuccessAddPlace}
|
|
258
|
+
handleSuccessDeletePlace={handleSuccessDeletePlace}
|
|
259
|
+
onClose={() => handleCloseModal()}
|
|
260
|
+
/>
|
|
261
|
+
</Modal>
|
|
262
|
+
</>
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export const BusinessPlaceGroup = (props) => {
|
|
267
|
+
const businessPlaceProps = {
|
|
268
|
+
...props,
|
|
269
|
+
UIComponent: BusinessPlaceGroupUI
|
|
270
|
+
}
|
|
271
|
+
return <BusinessPlaceGroupController {...businessPlaceProps} />
|
|
272
|
+
}
|