Skip to content

Commit 87dbbd8

Browse files
committed
refactor: only allowing snooze & unsnooze of a case
1 parent c283076 commit 87dbbd8

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

packages/app-builder/src/locales/en/cases.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@
128128
"sanction.state.refine_needed": "Refine needed",
129129
"snooze.title": "Snooze",
130130
"snooze.callout": "Snoozed until {{date}}",
131-
"snooze.modal.heading": "Should snooze ?",
132-
"unsnooze.callout": "By continuing, you will unsnooze the case",
133-
"unsnooze.title": "Unsnooze",
134-
"snooze.confirm": "Continue"
131+
"snooze.modal.heading": "Snooze until...",
132+
"unsnooze.callout": "By continuing, you will unsnooze this case",
133+
"unsnooze.title": "Unsnooze"
135134
}

packages/app-builder/src/locales/fr/cases.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"case_detail.history.event_detail.case_unsnoozed.title": "Réactivé",
127127
"snooze.callout": "Désactivé jusqu'à {{date}}",
128128
"snooze.confirm": "Continuer",
129-
"snooze.modal.heading": "Gérer l'activation",
129+
"snooze.modal.heading": "Désactiver jusqu'à...",
130130
"snooze.title": "Désactiver",
131131
"unsnooze.callout": "En continuant, vous réactiverez l'investigation",
132132
"unsnooze.title": "Réactiver",

packages/app-builder/src/routes/ressources+/cases+/edit-snooze.tsx

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { type ActionFunctionArgs } from '@remix-run/node';
66
import { useFetcher } from '@remix-run/react';
77
import { useForm } from '@tanstack/react-form';
88
import { type Namespace } from 'i18next';
9-
import { useState } from 'react';
109
import { useTranslation } from 'react-i18next';
11-
import { Button, Calendar, ModalV2, Switch } from 'ui-design-system';
10+
import { Button, Calendar, ModalV2 } from 'ui-design-system';
1211
import { Icon } from 'ui-icons';
1312
import { z } from 'zod';
1413

@@ -50,14 +49,13 @@ export function EditCaseSnooze({
5049
}: Pick<EditSnoozeForm, 'caseId'> & { snoozeUntil?: string }) {
5150
const { t } = useTranslation(handle.i18n);
5251
const fetcher = useFetcher<typeof action>();
53-
const [isSnoozing, shouldSnooze] = useState(true);
5452

5553
const form = useForm<EditSnoozeForm>({
5654
onSubmit: ({ value, formApi }) => {
5755
if (formApi.state.isValid) {
5856
const finalValue = {
5957
...value,
60-
snoozeUntil: isSnoozing ? value.snoozeUntil : null,
58+
snoozeUntil: snoozeUntil ? null : value.snoozeUntil,
6159
};
6260

6361
fetcher.submit(finalValue, {
@@ -73,19 +71,21 @@ export function EditCaseSnooze({
7371
onSubmitAsync: editSnoozeSchema,
7472
},
7573
defaultValues: {
76-
snoozeUntil: snoozeUntil ?? new Date().toISOString(),
74+
snoozeUntil: snoozeUntil ?? null,
7775
caseId: caseId,
7876
},
7977
});
8078

8179
return (
8280
<ModalV2.Root>
83-
<ModalV2.Trigger render={<Button variant="primary" />}>
81+
<ModalV2.Trigger render={<Button variant={snoozeUntil ? 'secondary' : 'primary'} />}>
8482
<Icon icon="snooze" className="size-5" aria-hidden />
85-
{t('cases:snooze.title')}
83+
{snoozeUntil ? t('cases:unsnooze.title') : t('cases:snooze.title')}
8684
</ModalV2.Trigger>
8785
<ModalV2.Content>
88-
<ModalV2.Title>{t('cases:snooze.modal.heading')}</ModalV2.Title>
86+
<ModalV2.Title>
87+
{snoozeUntil ? t('cases:unsnooze.title') : t('cases:snooze.modal.heading')}
88+
</ModalV2.Title>
8989
<form
9090
className="flex flex-col gap-6 p-6"
9191
onSubmit={(e) => {
@@ -94,30 +94,24 @@ export function EditCaseSnooze({
9494
form.handleSubmit();
9595
}}
9696
>
97-
<form.Field name="snoozeUntil">
98-
{(field) => (
99-
<div className="flex flex-col items-center gap-4">
100-
<div className="flex flex-row items-center gap-2">
101-
<span className="text-s font-semibold">{t('cases:unsnooze.title')}</span>
102-
<Switch onCheckedChange={shouldSnooze} checked={isSnoozing} />
103-
<span className="text-s font-semibold">{t('cases:snooze.title')}</span>
104-
</div>
105-
{isSnoozing ? (
97+
{snoozeUntil ? (
98+
<CalloutV2>{t('cases:unsnooze.callout')}</CalloutV2>
99+
) : (
100+
<form.Field name="snoozeUntil">
101+
{(field) => (
102+
<div className="flex flex-col items-center gap-4">
106103
<Calendar
107104
className="border-grey-90 w-fit rounded border p-2 shadow"
108105
mode="single"
109106
selected={new Date(field.state.value as string)}
110-
disabled={!isSnoozing}
111107
hidden={{ before: new Date() }}
112108
autoFocus
113109
onSelect={(d) => d && field.handleChange(d.toISOString())}
114110
/>
115-
) : (
116-
<CalloutV2>{t('cases:unsnooze.callout')}</CalloutV2>
117-
)}
118-
</div>
119-
)}
120-
</form.Field>
111+
</div>
112+
)}
113+
</form.Field>
114+
)}
121115
<div className="flex w-full flex-row gap-2">
122116
<ModalV2.Close
123117
render={
@@ -134,7 +128,7 @@ export function EditCaseSnooze({
134128
<ModalV2.Close
135129
render={<Button type="submit" className="flex-1 first-letter:capitalize" />}
136130
>
137-
{t('cases:snooze.confirm')}
131+
{snoozeUntil ? t('cases:unsnooze.title') : t('cases:snooze.title')}
138132
</ModalV2.Close>
139133
</div>
140134
</form>

0 commit comments

Comments
 (0)