@@ -2,18 +2,30 @@ import { useToast } from '@/components/toast'
2
2
import { SUB_BRANDING , UPSERT_SUB_BRANDING } from '@/fragments/subs'
3
3
import { useMutation , useQuery } from '@apollo/client'
4
4
import { subBrandingSchema } from '@/lib/validate'
5
- import { Form , Input , ColorPicker , SubmitButton } from '@/components/form'
5
+ import { Form , Input , ColorPicker , SubmitButton , BrandingUpload } from '@/components/form'
6
6
import AccordianItem from '@/components/accordian-item'
7
+ import Moon from '@/svgs/moon-fill.svg'
7
8
8
9
export default function TerritoryBrandingForm ( { sub } ) {
9
10
const [ upsertSubBranding ] = useMutation ( UPSERT_SUB_BRANDING )
10
11
const toaster = useToast ( )
11
12
12
- const { data } = useQuery ( SUB_BRANDING , {
13
+ const { data, loading } = useQuery ( SUB_BRANDING , {
13
14
variables : { subName : sub . name }
14
15
} )
15
16
16
- const subBranding = data ?. sub ?. branding
17
+ if ( loading ) {
18
+ return < Moon className = 'spin fill-grey' style = { { width : '1rem' , height : '1rem' } } />
19
+ }
20
+
21
+ const subBranding = data ?. subBranding || {
22
+ title : sub . name ,
23
+ description : sub . desc ,
24
+ primaryColor : '#FADA5E' ,
25
+ secondaryColor : '#F6911D' ,
26
+ logoId : null ,
27
+ faviconId : null
28
+ }
17
29
18
30
const onSubmit = async ( values ) => {
19
31
try {
@@ -23,27 +35,27 @@ export default function TerritoryBrandingForm ({ sub }) {
23
35
branding : {
24
36
title : values . title ,
25
37
description : values . description ,
26
- primaryColor : values . primary ,
27
- secondaryColor : values . secondary ,
38
+ primaryColor : values . primaryColor ,
39
+ secondaryColor : values . secondaryColor ,
28
40
logoId : values . logoId ,
29
41
faviconId : values . faviconId
30
42
}
31
43
}
32
44
} )
33
- toaster . success ( 'Branding updated successfully' )
45
+ toaster . success ( 'branding updated successfully' )
34
46
} catch ( error ) {
35
47
console . error ( error )
36
- toaster . danger ( 'Failed to update branding' , { error } )
48
+ toaster . danger ( 'failed to update branding' , { error } )
37
49
}
38
50
}
39
51
40
52
const initialValues = {
41
- title : subBranding ? .title || sub ?. name ,
42
- description : subBranding ? .description || '' ,
43
- primaryColor : subBranding ? .primaryColor || '#FADA5E' ,
44
- secondaryColor : subBranding ? .secondaryColor || '#F6911D' ,
45
- logoId : subBranding ? .logoId || null ,
46
- faviconId : subBranding ? .faviconId || null
53
+ title : subBranding . title ,
54
+ description : subBranding . description ,
55
+ primaryColor : subBranding . primaryColor ,
56
+ secondaryColor : subBranding . secondaryColor ,
57
+ logoId : subBranding . logoId ,
58
+ faviconId : subBranding . faviconId
47
59
}
48
60
49
61
return (
@@ -55,8 +67,8 @@ export default function TerritoryBrandingForm ({ sub }) {
55
67
< Input label = 'title' name = 'title' />
56
68
< Input label = 'description' name = 'description' />
57
69
< div className = 'row' >
58
- < ColorPicker groupClassName = 'col-4' label = 'primary color' name = 'primary ' />
59
- < ColorPicker groupClassName = 'col-4' label = 'secondary color' name = 'secondary ' />
70
+ < ColorPicker groupClassName = 'col-4' label = 'primary color' name = 'primaryColor ' />
71
+ < ColorPicker groupClassName = 'col-4' label = 'secondary color' name = 'secondaryColor ' />
60
72
</ div >
61
73
< AccordianItem
62
74
header = { < div className = 'fw-bold text-muted' > logo and favicon</ div > }
@@ -65,15 +77,13 @@ export default function TerritoryBrandingForm ({ sub }) {
65
77
< div className = 'col-2' >
66
78
< label className = 'form-label' > logo</ label >
67
79
< div style = { { position : 'relative' , width : '100px' , height : '100px' , border : '1px solid #dee2e6' , borderRadius : '5px' , overflow : 'hidden' } } >
68
- < p > placeholder</ p >
69
- { /* <BrandingUpload name='logoId' /> */ }
80
+ < BrandingUpload name = 'logoId' />
70
81
</ div >
71
82
</ div >
72
83
< div className = 'col-2' >
73
84
< label className = 'form-label' > favicon</ label >
74
85
< div style = { { position : 'relative' , width : '100px' , height : '100px' , border : '1px solid #dee2e6' , borderRadius : '5px' , overflow : 'hidden' } } >
75
- < p > placeholder</ p >
76
- { /* <BrandingUpload name='faviconId' /> */ }
86
+ < BrandingUpload name = 'faviconId' />
77
87
</ div >
78
88
</ div >
79
89
</ div >
0 commit comments