@@ -6,9 +6,8 @@ import { type ActionFunctionArgs } from '@remix-run/node';
6
6
import { useFetcher } from '@remix-run/react' ;
7
7
import { useForm } from '@tanstack/react-form' ;
8
8
import { type Namespace } from 'i18next' ;
9
- import { useState } from 'react' ;
10
9
import { useTranslation } from 'react-i18next' ;
11
- import { Button , Calendar , ModalV2 , Switch } from 'ui-design-system' ;
10
+ import { Button , Calendar , ModalV2 } from 'ui-design-system' ;
12
11
import { Icon } from 'ui-icons' ;
13
12
import { z } from 'zod' ;
14
13
@@ -50,14 +49,13 @@ export function EditCaseSnooze({
50
49
} : Pick < EditSnoozeForm , 'caseId' > & { snoozeUntil ?: string } ) {
51
50
const { t } = useTranslation ( handle . i18n ) ;
52
51
const fetcher = useFetcher < typeof action > ( ) ;
53
- const [ isSnoozing , shouldSnooze ] = useState ( true ) ;
54
52
55
53
const form = useForm < EditSnoozeForm > ( {
56
54
onSubmit : ( { value, formApi } ) => {
57
55
if ( formApi . state . isValid ) {
58
56
const finalValue = {
59
57
...value ,
60
- snoozeUntil : isSnoozing ? value . snoozeUntil : null ,
58
+ snoozeUntil : snoozeUntil ? null : value . snoozeUntil ,
61
59
} ;
62
60
63
61
fetcher . submit ( finalValue , {
@@ -73,19 +71,21 @@ export function EditCaseSnooze({
73
71
onSubmitAsync : editSnoozeSchema ,
74
72
} ,
75
73
defaultValues : {
76
- snoozeUntil : snoozeUntil ?? new Date ( ) . toISOString ( ) ,
74
+ snoozeUntil : snoozeUntil ?? null ,
77
75
caseId : caseId ,
78
76
} ,
79
77
} ) ;
80
78
81
79
return (
82
80
< ModalV2 . Root >
83
- < ModalV2 . Trigger render = { < Button variant = " primary" /> } >
81
+ < ModalV2 . Trigger render = { < Button variant = { snoozeUntil ? 'secondary' : ' primary' } /> } >
84
82
< Icon icon = "snooze" className = "size-5" aria-hidden />
85
- { t ( 'cases:snooze.title' ) }
83
+ { snoozeUntil ? t ( 'cases:unsnooze.title' ) : t ( 'cases:snooze.title' ) }
86
84
</ ModalV2 . Trigger >
87
85
< 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 >
89
89
< form
90
90
className = "flex flex-col gap-6 p-6"
91
91
onSubmit = { ( e ) => {
@@ -94,30 +94,24 @@ export function EditCaseSnooze({
94
94
form . handleSubmit ( ) ;
95
95
} }
96
96
>
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" >
106
103
< Calendar
107
104
className = "border-grey-90 w-fit rounded border p-2 shadow"
108
105
mode = "single"
109
106
selected = { new Date ( field . state . value as string ) }
110
- disabled = { ! isSnoozing }
111
107
hidden = { { before : new Date ( ) } }
112
108
autoFocus
113
109
onSelect = { ( d ) => d && field . handleChange ( d . toISOString ( ) ) }
114
110
/>
115
- ) : (
116
- < CalloutV2 > { t ( 'cases:unsnooze.callout' ) } </ CalloutV2 >
117
- ) }
118
- </ div >
119
- ) }
120
- </ form . Field >
111
+ </ div >
112
+ ) }
113
+ </ form . Field >
114
+ ) }
121
115
< div className = "flex w-full flex-row gap-2" >
122
116
< ModalV2 . Close
123
117
render = {
@@ -134,7 +128,7 @@ export function EditCaseSnooze({
134
128
< ModalV2 . Close
135
129
render = { < Button type = "submit" className = "flex-1 first-letter:capitalize" /> }
136
130
>
137
- { t ( 'cases:snooze.confirm ' ) }
131
+ { snoozeUntil ? t ( 'cases:unsnooze.title' ) : t ( 'cases: snooze.title ') }
138
132
</ ModalV2 . Close >
139
133
</ div >
140
134
</ form >
0 commit comments