Skip to content

Commit 5911718

Browse files
committed
ISS-1254: watermark enabled toggle on creation
1 parent e486621 commit 5911718

5 files changed

Lines changed: 118 additions & 25 deletions

File tree

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

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ import { zodResolver } from '@hookform/resolvers/zod'
99
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '@repo/ui/sheet'
1010
import { useRouter, useSearchParams } from 'next/navigation'
1111
import { TrustCenterDocTrustCenterDocumentVisibility, TrustCenterDocWatermarkStatus } from '@repo/codegen/src/schema'
12-
import { useCreateTrustCenterDoc, useDeleteTrustCenterDoc, useGetTrustCenter, useGetTrustCenterDocById, useUpdateTrustCenterDoc } from '@/lib/graphql-hooks/trust-center'
12+
import {
13+
useCreateTrustCenterDoc,
14+
useDeleteTrustCenterDoc,
15+
useGetTrustCenter,
16+
useGetTrustCenterDocById,
17+
useUpdateTrustCenterDoc,
18+
useUpdateTrustCenterWatermarkConfig,
19+
} from '@/lib/graphql-hooks/trust-center'
1320
import { useNotification } from '@/hooks/useNotification'
1421
import { parseErrorMessage } from '@/utils/graphQlErrorMatcher'
1522
import { ConfirmationDialog } from '@repo/ui/confirmation-dialog'
@@ -20,11 +27,12 @@ import { VisibilityField } from './form-fields/visibility-field'
2027
import { TagsField } from './form-fields/tags-field'
2128
import { FileField } from './form-fields/file-field'
2229
import { TUploadedFile } from '@/components/pages/protected/evidence/upload/types/TUploadedFile'
23-
import DocumentsWatermarkStatusChip from '../../documents-watermark-status-chip.'
2430
import { Label } from '@repo/ui/label'
2531
import { useAccountRoles } from '@/lib/query-hooks/permissions'
2632
import { ObjectEnum } from '@/lib/authz/enums/object-enum'
2733
import { canDelete, canEdit } from '@/lib/authz/utils'
34+
import { Switch } from '@repo/ui/switch'
35+
import DocumentsWatermarkStatusChip from '../../documents-watermark-status-chip.'
2836

2937
const schema = z.object({
3038
title: z.string().min(1, 'Title is required'),
@@ -60,6 +68,7 @@ export const CreateDocumentSheet: React.FC = () => {
6068
const { mutateAsync: createDoc } = useCreateTrustCenterDoc()
6169
const { mutateAsync: updateDoc } = useUpdateTrustCenterDoc()
6270
const { mutateAsync: deleteDoc } = useDeleteTrustCenterDoc()
71+
const { mutateAsync: updateWatermark } = useUpdateTrustCenterWatermarkConfig()
6372

6473
const { data: trustCenterData } = useGetTrustCenter()
6574
const { data: documentData } = useGetTrustCenterDocById({
@@ -68,7 +77,9 @@ export const CreateDocumentSheet: React.FC = () => {
6877
})
6978

7079
const trustCenterID = trustCenterData?.trustCenters?.edges?.[0]?.node?.id ?? null
71-
80+
const watermarkConfigId = trustCenterData?.trustCenters?.edges?.[0]?.node?.watermarkConfig?.id ?? null
81+
const watermarkEnabled = trustCenterData?.trustCenters?.edges?.[0]?.node?.watermarkConfig?.isEnabled ?? null
82+
const [isWatermarkEnabled, setWatermarkEnabled] = useState(watermarkEnabled ?? false)
7283
const formMethods = useForm<FormData>({
7384
resolver: zodResolver(schema),
7485
defaultValues: {
@@ -205,6 +216,34 @@ export const CreateDocumentSheet: React.FC = () => {
205216
if (documentId || isCreateMode) setOpen(true)
206217
}, [documentId, isCreateMode])
207218

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+
208247
return (
209248
<Sheet open={open} onOpenChange={handleOpenChange}>
210249
<SheetContent side="right" className="w-[420px] sm:w-[480px] overflow-y-auto">
@@ -321,10 +360,24 @@ export const CreateDocumentSheet: React.FC = () => {
321360
<CategoryField isEditing={isEditing || isCreateMode} />
322361
<VisibilityField isEditing={isEditing || isCreateMode} />
323362
<TagsField isEditing={isEditing || isCreateMode} />
324-
<div className="flex flex-col gap-2">
325-
<Label>Watermark status</Label>
326-
<DocumentsWatermarkStatusChip className="self-start" status={documentData?.trustCenterDoc?.watermarkStatus ?? undefined} />
327-
</div>
363+
{isCreateMode && (
364+
<div className="flex flex-col gap-2">
365+
<Label>Watermark enabled</Label>
366+
<Switch
367+
checked={isWatermarkEnabled}
368+
onCheckedChange={(checked) => {
369+
setWatermarkEnabled(checked)
370+
handleToggleWatermarkEnabled(checked)
371+
}}
372+
/>
373+
</div>
374+
)}
375+
{isEditMode && (
376+
<div className="flex flex-col gap-2">
377+
<Label>Watermark status</Label>
378+
<DocumentsWatermarkStatusChip className="self-start" status={documentData?.trustCenterDoc?.watermarkStatus ?? undefined} />
379+
</div>
380+
)}
328381
{isEditMode ? <DocumentFiles documentId={documentId!} editAllowed={isEditAllowed} /> : <FileField uploadedFile={uploadedFile} isEditing={isEditing} onFileUpload={handleFileUpload} />}
329382
</form>
330383
</FormProvider>

apps/console/src/components/pages/protected/trust-center/settings/brand-settings-page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const BrandSettingsPage: React.FC = () => {
7474
setSecondaryBackground(setting.secondaryBackgroundColor || '#f0f0e0')
7575
setFont(setting.font || 'outfit')
7676
setEasyColor(setting.primaryColor || '#f0f0e0')
77+
setSelectedThemeType(setting.themeMode ?? TrustCenterSettingTrustCenterThemeMode.EASY)
7778
}
7879
}, [setting])
7980

packages/codegen/query/trust-center.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const GET_TRUST_CENTER = gql`
7979
color
8080
opacity
8181
rotation
82+
isEnabled
8283
}
8384
}
8485
}

packages/codegen/src/introspectionschema.json

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182180,7 +182180,7 @@
182180182180
},
182181182181
{
182182182182
"name": "createBulkCSVTrustcenterEntity",
182183-
"description": "Create multiple new trustcenterEntities via file upload",
182183+
"description": "Create multiple new trustcenterEntitys via file upload",
182184182184
"args": [
182185182185
{
182186182186
"name": "input",
@@ -184253,7 +184253,7 @@
184253184253
},
184254184254
{
184255184255
"name": "createBulkTrustcenterEntity",
184256-
"description": "Create multiple new trustcenterEntities",
184256+
"description": "Create multiple new trustcenterEntitys",
184257184257
"args": [
184258184258
{
184259184259
"name": "input",
@@ -339866,7 +339866,7 @@
339866339866
"fields": [
339867339867
{
339868339868
"name": "trustcenterEntities",
339869-
"description": "Created trustcenterEntities",
339869+
"description": "Created trustcenterEntitys",
339870339870
"args": [],
339871339871
"type": {
339872339872
"kind": "LIST",
@@ -430778,7 +430778,12 @@
430778430778
"name": "deprecated",
430779430779
"description": "Marks an element of a GraphQL schema as no longer supported.",
430780430780
"isRepeatable": false,
430781-
"locations": ["ARGUMENT_DEFINITION", "ENUM_VALUE", "FIELD_DEFINITION", "INPUT_FIELD_DEFINITION"],
430781+
"locations": [
430782+
"ARGUMENT_DEFINITION",
430783+
"ENUM_VALUE",
430784+
"FIELD_DEFINITION",
430785+
"INPUT_FIELD_DEFINITION"
430786+
],
430782430787
"args": [
430783430788
{
430784430789
"name": "reason",
@@ -430798,7 +430803,9 @@
430798430803
"name": "externalReadOnly",
430799430804
"description": "Indicates is the input field is read-only by non-system admin users for system-owned objects\nIf an input is marked as @externalReadOnly, only system-admin users\ncan set the field if the object is marked as source == ControlSourceFramework",
430800430805
"isRepeatable": false,
430801-
"locations": ["INPUT_FIELD_DEFINITION"],
430806+
"locations": [
430807+
"INPUT_FIELD_DEFINITION"
430808+
],
430802430809
"args": [
430803430810
{
430804430811
"name": "source",
@@ -430818,7 +430825,10 @@
430818430825
"name": "externalSource",
430819430826
"description": "Indicates that this field cannot be set on the input, and comes from an external source\nThis does not prevent the viewing of the field",
430820430827
"isRepeatable": false,
430821-
"locations": ["FIELD_DEFINITION", "OBJECT"],
430828+
"locations": [
430829+
"FIELD_DEFINITION",
430830+
"OBJECT"
430831+
],
430822430832
"args": [
430823430833
{
430824430834
"name": "source",
@@ -430838,7 +430848,10 @@
430838430848
"name": "goField",
430839430849
"description": null,
430840430850
"isRepeatable": false,
430841-
"locations": ["FIELD_DEFINITION", "INPUT_FIELD_DEFINITION"],
430851+
"locations": [
430852+
"FIELD_DEFINITION",
430853+
"INPUT_FIELD_DEFINITION"
430854+
],
430842430855
"args": [
430843430856
{
430844430857
"name": "forceResolver",
@@ -430882,7 +430895,14 @@
430882430895
"name": "goModel",
430883430896
"description": null,
430884430897
"isRepeatable": false,
430885-
"locations": ["ENUM", "INPUT_OBJECT", "INTERFACE", "OBJECT", "SCALAR", "UNION"],
430898+
"locations": [
430899+
"ENUM",
430900+
"INPUT_OBJECT",
430901+
"INTERFACE",
430902+
"OBJECT",
430903+
"SCALAR",
430904+
"UNION"
430905+
],
430886430906
"args": [
430887430907
{
430888430908
"name": "forceGenerate",
@@ -430934,7 +430954,10 @@
430934430954
"name": "hidden",
430935430955
"description": "Indicates if a field will be returned in a query, if true, only system-admins\ncan retrieve the value",
430936430956
"isRepeatable": false,
430937-
"locations": ["FIELD_DEFINITION", "OBJECT"],
430957+
"locations": [
430958+
"FIELD_DEFINITION",
430959+
"OBJECT"
430960+
],
430938430961
"args": [
430939430962
{
430940430963
"name": "if",
@@ -430954,7 +430977,11 @@
430954430977
"name": "include",
430955430978
"description": "Directs the executor to include this field or fragment only when the `if` argument is true.",
430956430979
"isRepeatable": false,
430957-
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
430980+
"locations": [
430981+
"FIELD",
430982+
"FRAGMENT_SPREAD",
430983+
"INLINE_FRAGMENT"
430984+
],
430958430985
"args": [
430959430986
{
430960430987
"name": "if",
@@ -430978,21 +431005,29 @@
430978431005
"name": "oneOf",
430979431006
"description": "Indicates exactly one field must be supplied and this field must not be `null`.",
430980431007
"isRepeatable": false,
430981-
"locations": ["INPUT_OBJECT"],
431008+
"locations": [
431009+
"INPUT_OBJECT"
431010+
],
430982431011
"args": []
430983431012
},
430984431013
{
430985431014
"name": "readOnly",
430986431015
"description": "Indicates is the input field is read-only by non-system admin users.\nIf an input is marked as @readOnly, only system-admin users\ncan set the field",
430987431016
"isRepeatable": false,
430988-
"locations": ["INPUT_FIELD_DEFINITION"],
431017+
"locations": [
431018+
"INPUT_FIELD_DEFINITION"
431019+
],
430989431020
"args": []
430990431021
},
430991431022
{
430992431023
"name": "skip",
430993431024
"description": "Directs the executor to skip this field or fragment when the `if` argument is true.",
430994431025
"isRepeatable": false,
430995-
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
431026+
"locations": [
431027+
"FIELD",
431028+
"FRAGMENT_SPREAD",
431029+
"INLINE_FRAGMENT"
431030+
],
430996431031
"args": [
430997431032
{
430998431033
"name": "if",
@@ -431016,7 +431051,9 @@
431016431051
"name": "specifiedBy",
431017431052
"description": "Exposes a URL that specifies the behavior of this scalar.",
431018431053
"isRepeatable": false,
431019-
"locations": ["SCALAR"],
431054+
"locations": [
431055+
"SCALAR"
431056+
],
431020431057
"args": [
431021431058
{
431022431059
"name": "url",
@@ -431038,4 +431075,4 @@
431038431075
}
431039431076
]
431040431077
}
431041-
}
431078+
}

packages/codegen/src/schema.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19066,7 +19066,7 @@ export interface Mutation {
1906619066
createBulkCSVTrustCenterDoc: TrustCenterDocBulkCreatePayload
1906719067
/** Create multiple new trustCenterSubprocessors via file upload */
1906819068
createBulkCSVTrustCenterSubprocessor: TrustCenterSubprocessorBulkCreatePayload
19069-
/** Create multiple new trustcenterEntities via file upload */
19069+
/** Create multiple new trustcenterEntitys via file upload */
1907019070
createBulkCSVTrustcenterEntity: TrustcenterEntityBulkCreatePayload
1907119071
/** Create multiple new userSettings via file upload */
1907219072
createBulkCSVUserSetting: UserSettingBulkCreatePayload
@@ -19180,7 +19180,7 @@ export interface Mutation {
1918019180
createBulkTrustCenterDoc: TrustCenterDocBulkCreatePayload
1918119181
/** Create multiple new trustCenterSubprocessors */
1918219182
createBulkTrustCenterSubprocessor: TrustCenterSubprocessorBulkCreatePayload
19183-
/** Create multiple new trustcenterEntities */
19183+
/** Create multiple new trustcenterEntitys */
1918419184
createBulkTrustcenterEntity: TrustcenterEntityBulkCreatePayload
1918519185
/** Create multiple new userSettings */
1918619186
createBulkUserSetting: UserSettingBulkCreatePayload
@@ -36509,7 +36509,7 @@ export interface TrustcenterEntity extends Node {
3650936509
/** Return response for createBulkTrustcenterEntity mutation */
3651036510
export interface TrustcenterEntityBulkCreatePayload {
3651136511
__typename?: 'TrustcenterEntityBulkCreatePayload'
36512-
/** Created trustcenterEntities */
36512+
/** Created trustcenterEntitys */
3651336513
trustcenterEntities?: Maybe<Array<TrustcenterEntity>>
3651436514
}
3651536515

@@ -50252,6 +50252,7 @@ export type GetTrustCenterQuery = {
5025250252
color?: string | null
5025350253
opacity?: number | null
5025450254
rotation?: number | null
50255+
isEnabled?: boolean | null
5025550256
file?: { __typename?: 'File'; presignedURL?: string | null } | null
5025650257
} | null
5025750258
} | null

0 commit comments

Comments
 (0)