test commit
This commit is contained in:
@@ -10,14 +10,18 @@ import {
|
||||
fetchUserNotificationSettings,
|
||||
updateUserNotificationSettings,
|
||||
} from '@/entities/notification/api/notifications-api'
|
||||
import type { UserNotificationSettings } from '@/entities/notification/api/notifications-api'
|
||||
|
||||
const eventFields = [
|
||||
{ key: 'orderCreated' as const, label: 'Заказ создан' },
|
||||
{ key: 'orderStatusChanged' as const, label: 'Изменение статуса заказа' },
|
||||
{ key: 'orderMessageReceived' as const, label: 'Сообщение в чате заказа' },
|
||||
{ key: 'paymentStatusChanged' as const, label: 'Изменение статуса оплаты' },
|
||||
{ key: 'deliveryFeeAdjusted' as const, label: 'Корректировка стоимости доставки' },
|
||||
]
|
||||
function isOrderStatusChangesOn(s: UserNotificationSettings): boolean {
|
||||
return s.orderCreated && s.orderStatusChanged && s.paymentStatusChanged && s.deliveryFeeAdjusted
|
||||
}
|
||||
|
||||
const orderStatusChangesPayload = (on: boolean) => ({
|
||||
orderCreated: on,
|
||||
orderStatusChanged: on,
|
||||
paymentStatusChanged: on,
|
||||
deliveryFeeAdjusted: on,
|
||||
})
|
||||
|
||||
export function NotificationsPage() {
|
||||
const queryClient = useQueryClient()
|
||||
@@ -45,9 +49,11 @@ export function NotificationsPage() {
|
||||
|
||||
const handleToggle = (field: string, value: boolean) => {
|
||||
setError(null)
|
||||
mutation.mutate({ [field]: value } as Record<string, boolean>)
|
||||
mutation.mutate({ [field]: value })
|
||||
}
|
||||
|
||||
const statusChangesOn = isOrderStatusChangesOn(settings)
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h4" gutterBottom>
|
||||
@@ -80,19 +86,26 @@ export function NotificationsPage() {
|
||||
</Box>
|
||||
|
||||
<Box sx={{ pl: 4 }}>
|
||||
{eventFields.map(({ key, label }) => (
|
||||
<FormControlLabel
|
||||
key={key}
|
||||
control={
|
||||
<Switch
|
||||
checked={settings[key]}
|
||||
disabled={!settings.globalEnabled}
|
||||
onChange={(e) => handleToggle(key, e.target.checked)}
|
||||
/>
|
||||
}
|
||||
label={label}
|
||||
/>
|
||||
))}
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
checked={statusChangesOn}
|
||||
disabled={!settings.globalEnabled}
|
||||
onChange={(e) => mutation.mutate(orderStatusChangesPayload(e.target.checked))}
|
||||
/>
|
||||
}
|
||||
label="Изменения статуса заказа"
|
||||
/>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
checked={settings.orderMessageReceived}
|
||||
disabled={!settings.globalEnabled}
|
||||
onChange={(e) => handleToggle('orderMessageReceived', e.target.checked)}
|
||||
/>
|
||||
}
|
||||
label="Сообщения в чате заказа"
|
||||
/>
|
||||
</Box>
|
||||
</Stack>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user