Skip to content

Commit a614657

Browse files
committed
ISS-1254: added invalidation
1 parent 5911718 commit a614657

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

apps/console/src/components/pages/protected/trust-center/reports-and-certifications/sheet/create-document.sheet.tsx

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { ObjectEnum } from '@/lib/authz/enums/object-enum'
3333
import { canDelete, canEdit } from '@/lib/authz/utils'
3434
import { Switch } from '@repo/ui/switch'
3535
import DocumentsWatermarkStatusChip from '../../documents-watermark-status-chip.'
36+
import { useQueryClient } from '@tanstack/react-query'
3637

3738
const schema = z.object({
3839
title: z.string().min(1, 'Title is required'),
@@ -69,6 +70,7 @@ export const CreateDocumentSheet: React.FC = () => {
6970
const { mutateAsync: updateDoc } = useUpdateTrustCenterDoc()
7071
const { mutateAsync: deleteDoc } = useDeleteTrustCenterDoc()
7172
const { mutateAsync: updateWatermark } = useUpdateTrustCenterWatermarkConfig()
73+
const queryClient = useQueryClient()
7274

7375
const { data: trustCenterData } = useGetTrustCenter()
7476
const { data: documentData } = useGetTrustCenterDocById({
@@ -78,6 +80,7 @@ export const CreateDocumentSheet: React.FC = () => {
7880

7981
const trustCenterID = trustCenterData?.trustCenters?.edges?.[0]?.node?.id ?? null
8082
const watermarkConfigId = trustCenterData?.trustCenters?.edges?.[0]?.node?.watermarkConfig?.id ?? null
83+
console.log(trustCenterData?.trustCenters?.edges?.[0]?.node?.watermarkConfig)
8184
const watermarkEnabled = trustCenterData?.trustCenters?.edges?.[0]?.node?.watermarkConfig?.isEnabled ?? null
8285
const [isWatermarkEnabled, setWatermarkEnabled] = useState(watermarkEnabled ?? false)
8386
const formMethods = useForm<FormData>({
@@ -167,6 +170,35 @@ export const CreateDocumentSheet: React.FC = () => {
167170
}
168171
}
169172

173+
const handleToggleWatermarkEnabled = async (enabled: boolean) => {
174+
if (!watermarkConfigId) {
175+
errorNotification({
176+
title: 'Watermark config ID missing',
177+
description: 'Watermark config ID missing',
178+
})
179+
return
180+
}
181+
182+
try {
183+
await updateWatermark({
184+
updateTrustCenterWatermarkConfigId: watermarkConfigId,
185+
input: {
186+
isEnabled: enabled,
187+
},
188+
})
189+
successNotification({
190+
title: 'Watermark config updated successfully',
191+
})
192+
queryClient.invalidateQueries({ queryKey: ['trustCenter'] })
193+
} catch (error) {
194+
const errorMessage = parseErrorMessage(error)
195+
errorNotification({
196+
title: 'Error',
197+
description: errorMessage,
198+
})
199+
}
200+
}
201+
170202
const prefillForm = useCallback(() => {
171203
const doc = documentData?.trustCenterDoc
172204
reset({
@@ -216,34 +248,6 @@ export const CreateDocumentSheet: React.FC = () => {
216248
if (documentId || isCreateMode) setOpen(true)
217249
}, [documentId, isCreateMode])
218250

219-
const handleToggleWatermarkEnabled = async (enabled: boolean) => {
220-
if (!watermarkConfigId) {
221-
errorNotification({
222-
title: 'Watermark config ID missing',
223-
description: 'Watermark config ID missing',
224-
})
225-
return
226-
}
227-
228-
try {
229-
await updateWatermark({
230-
updateTrustCenterWatermarkConfigId: watermarkConfigId,
231-
input: {
232-
isEnabled: enabled,
233-
},
234-
})
235-
successNotification({
236-
title: 'Watermark config updated successfully',
237-
})
238-
} catch (error) {
239-
const errorMessage = parseErrorMessage(error)
240-
errorNotification({
241-
title: 'Error',
242-
description: errorMessage,
243-
})
244-
}
245-
}
246-
247251
return (
248252
<Sheet open={open} onOpenChange={handleOpenChange}>
249253
<SheetContent side="right" className="w-[420px] sm:w-[480px] overflow-y-auto">

0 commit comments

Comments
 (0)