Skip to content
Snippets Groups Projects

fix(ux): customPopup

Merged Bastien DUMONT requested to merge rework-custom-popup into dev
All threads resolved!
4 files
+ 79
65
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -18,6 +18,7 @@ import {
@@ -18,6 +18,7 @@ import {
Option,
Option,
durationEnum,
durationEnum,
durationType,
durationType,
 
mapDuration,
} from '../../models/durationOptions.model'
} from '../../models/durationOptions.model'
import { IPartnersInfo } from '../../models/partnersInfo.model'
import { IPartnersInfo } from '../../models/partnersInfo.model'
import { CustomPopupService } from '../../services/customPopup.service'
import { CustomPopupService } from '../../services/customPopup.service'
@@ -54,15 +55,15 @@ const Popups: React.FC = () => {
@@ -54,15 +55,15 @@ const Popups: React.FC = () => {
notification_activated: false,
notification_activated: false,
})
})
const [previousEndDate, setPreviousEndDate] = useState<string>()
const [previousEndDate, setPreviousEndDate] = useState<string>()
 
const [popupDuration, setPopupDuration] = useState<PopupDuration>({
 
type: durationEnum.infinite,
 
duration: 5,
 
})
const [customPopup, setCustomPopup] = useState<ICustomPopup>({
const [customPopup, setCustomPopup] = useState<ICustomPopup>({
popupEnabled: false,
popupEnabled: false,
title: '',
title: '',
description: '',
description: '',
endDate: DateTime.local().toISO(),
endDate: DateTime.local().plus({ days: 365 }).toISO(),
})
const [popupDuration, setPopupDuration] = useState<PopupDuration>({
type: durationEnum.hours,
duration: 0,
})
})
const isPartnerNotificationOn = () =>
const isPartnerNotificationOn = () =>
@@ -135,19 +136,25 @@ const Popups: React.FC = () => {
@@ -135,19 +136,25 @@ const Popups: React.FC = () => {
if (user) {
if (user) {
const partnersInfoService = new PartnersInfoService()
const partnersInfoService = new PartnersInfoService()
const customPopupService = new CustomPopupService()
const customPopupService = new CustomPopupService()
const partnersInfoData = await partnersInfoService.getPartnersInfo()
const previousPartnersInfo = await partnersInfoService.getPartnersInfo()
const customPopupData = await customPopupService.getCustomPopupInfo()
const previousPopup = await customPopupService.getCustomPopupInfo()
if (partnersInfoData) {
if (previousPartnersInfo) {
setPartnersInfo({
setPartnersInfo({
...partnersInfoData,
...previousPartnersInfo,
})
})
}
}
if (customPopupData) {
if (previousPopup) {
 
const isOutdated = isPopupOutdated(previousPopup.endDate)
 
/** If outdated, set value to false, otherwise, set it to its value */
 
const isEnabled = isOutdated ? false : previousPopup.popupEnabled
setCustomPopup({
setCustomPopup({
...customPopupData,
title: previousPopup.title,
 
description: previousPopup.description,
 
endDate: customPopup.endDate,
 
popupEnabled: isEnabled,
})
})
setPreviousEndDate(customPopupData.endDate || undefined)
setPreviousEndDate(previousPopup.endDate || undefined)
}
}
}
}
setIsLoading(false)
setIsLoading(false)
@@ -190,9 +197,7 @@ const Popups: React.FC = () => {
@@ -190,9 +197,7 @@ const Popups: React.FC = () => {
}))
}))
}
}
/**
/** Handles duration change */
* Handles duration change
*/
useEffect(() => {
useEffect(() => {
const now = DateTime.local()
const now = DateTime.local()
let newDate: DateTime
let newDate: DateTime
@@ -200,7 +205,7 @@ const Popups: React.FC = () => {
@@ -200,7 +205,7 @@ const Popups: React.FC = () => {
newDate = now.plus({
newDate = now.plus({
[popupDuration.type]: popupDuration.duration,
[popupDuration.type]: popupDuration.duration,
})
})
} else if (popupDuration.type === 'infinite') {
} else {
newDate = now.plus({
newDate = now.plus({
years: 1,
years: 1,
})
})
@@ -323,6 +328,51 @@ const Popups: React.FC = () => {
@@ -323,6 +328,51 @@ const Popups: React.FC = () => {
getRemainingDuration(previousEndDate)}
getRemainingDuration(previousEndDate)}
</FormGroup>
</FormGroup>
 
<div className="popupEndDate">
 
<h4>Durée</h4>
 
<div>
 
<FormControl style={{ flexDirection: 'row', gap: '1rem' }}>
 
<NativeSelect
 
inputProps={{
 
name: 'age',
 
id: 'uncontrolled-native',
 
}}
 
onChange={event => handleSelectChange(event)}
 
value={popupDuration.type}
 
>
 
{OPTIONS.map(option => (
 
<option key={option.value} value={option.value}>
 
{option.label}
 
</option>
 
))}
 
</NativeSelect>
 
 
<TextField
 
style={{ width: '6rem' }}
 
inputProps={{
 
inputMode: 'numeric',
 
pattern: '[0-9]*',
 
}}
 
id="outlined-number"
 
type="number"
 
label={mapDuration[popupDuration.type]}
 
InputLabelProps={{
 
shrink: true,
 
}}
 
value={popupDuration.duration}
 
disabled={popupDuration.type === 'infinite'}
 
onChange={e =>
 
setPopupDuration(prev => ({
 
...prev,
 
duration: Number(e.target.value),
 
}))
 
}
 
/>
 
</FormControl>
 
</div>
 
</div>
 
 
<h4>Contenu</h4>
<div className="popupTitle">
<div className="popupTitle">
<TextField
<TextField
type="text"
type="text"
@@ -347,48 +397,6 @@ const Popups: React.FC = () => {
@@ -347,48 +397,6 @@ const Popups: React.FC = () => {
type="custom_popup"
type="custom_popup"
/>
/>
</div>
</div>
<div className="popupEndDate">
<label htmlFor="title">Nouvelle Durée</label>
<div>
<FormControl style={{ flexDirection: 'row', gap: '1rem' }}>
<NativeSelect
inputProps={{
name: 'age',
id: 'uncontrolled-native',
}}
onChange={event => handleSelectChange(event)}
>
{OPTIONS.map(option => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</NativeSelect>
{popupDuration.type !== 'infinite' && (
<TextField
inputProps={{
inputMode: 'numeric',
pattern: '[0-9]*',
}}
id="outlined-number"
type="number"
InputLabelProps={{
shrink: true,
}}
value={popupDuration.duration}
onChange={e =>
setPopupDuration(prev => ({
...prev,
duration: Number(e.target.value),
}))
}
/>
)}
</FormControl>
</div>
</div>
</div>
</div>
<div className="buttons">
<div className="buttons">
Loading