@@ -2,43 +2,45 @@ import { useEffect, useMemo, useCallback } from "react";
2
2
import { useForm } from "react-hook-form" ;
3
3
import { Layout as DashboardLayout } from "/src/layouts/index.js" ;
4
4
import CippFormPage from "/src/components/CippFormPages/CippFormPage" ;
5
+ import CippFormSkeleton from "/src/components/CippFormPages/CippFormSkeleton" ;
5
6
import ContactFormLayout from "/src/components/CippFormPages/CippAddEditContact" ;
6
7
import { ApiGetCall } from "../../../../api/ApiCall" ;
7
8
import countryList from "/src/data/countryList.json" ;
8
9
import { useRouter } from "next/router" ;
9
10
10
- const countryLookup = new Map (
11
- countryList . map ( country => [ country . Name , country . Code ] )
12
- ) ;
11
+ const countryLookup = new Map ( countryList . map ( ( country ) => [ country . Name , country . Code ] ) ) ;
13
12
14
13
const EditContactTemplate = ( ) => {
15
14
const router = useRouter ( ) ;
16
15
const { id } = router . query ;
17
-
16
+
18
17
const contactTemplateInfo = ApiGetCall ( {
19
18
url : `/api/ListContactTemplates?id=${ id } ` ,
20
19
queryKey : `ListContactTemplates-${ id } ` ,
21
20
waiting : ! ! id ,
22
21
} ) ;
23
22
24
- const defaultFormValues = useMemo ( ( ) => ( {
25
- displayName : "" ,
26
- firstName : "" ,
27
- lastName : "" ,
28
- email : "" ,
29
- hidefromGAL : false ,
30
- streetAddress : "" ,
31
- postalCode : "" ,
32
- city : "" ,
33
- state : "" ,
34
- country : "" ,
35
- companyName : "" ,
36
- mobilePhone : "" ,
37
- businessPhone : "" ,
38
- jobTitle : "" ,
39
- website : "" ,
40
- mailTip : "" ,
41
- } ) , [ ] ) ;
23
+ const defaultFormValues = useMemo (
24
+ ( ) => ( {
25
+ displayName : "" ,
26
+ firstName : "" ,
27
+ lastName : "" ,
28
+ email : "" ,
29
+ hidefromGAL : false ,
30
+ streetAddress : "" ,
31
+ postalCode : "" ,
32
+ city : "" ,
33
+ state : "" ,
34
+ country : "" ,
35
+ companyName : "" ,
36
+ mobilePhone : "" ,
37
+ businessPhone : "" ,
38
+ jobTitle : "" ,
39
+ website : "" ,
40
+ mailTip : "" ,
41
+ } ) ,
42
+ [ ]
43
+ ) ;
42
44
43
45
const formControl = useForm ( {
44
46
mode : "onChange" ,
@@ -52,12 +54,14 @@ const EditContactTemplate = () => {
52
54
}
53
55
54
56
// Handle both single object (when fetching by ID) and array responses
55
- const contact = Array . isArray ( contactTemplateInfo . data ) ? contactTemplateInfo . data [ 0 ] : contactTemplateInfo . data ;
57
+ const contact = Array . isArray ( contactTemplateInfo . data )
58
+ ? contactTemplateInfo . data [ 0 ]
59
+ : contactTemplateInfo . data ;
56
60
const address = contact . addresses ?. [ 0 ] || { } ;
57
61
const phones = contact . phones || [ ] ;
58
-
62
+
59
63
// Use Map for O(1) phone lookup
60
- const phoneMap = new Map ( phones . map ( p => [ p . type , p . number ] ) ) ;
64
+ const phoneMap = new Map ( phones . map ( ( p ) => [ p . type , p . number ] ) ) ;
61
65
62
66
return {
63
67
ContactTemplateID : id || "" ,
@@ -70,9 +74,7 @@ const EditContactTemplate = () => {
70
74
postalCode : address . postalCode || "" ,
71
75
city : address . city || "" ,
72
76
state : address . state || "" ,
73
- country : address . countryOrRegion
74
- ? countryLookup . get ( address . countryOrRegion ) || ""
75
- : "" ,
77
+ country : address . countryOrRegion ? countryLookup . get ( address . countryOrRegion ) || "" : "" ,
76
78
companyName : contact . companyName || "" ,
77
79
mobilePhone : phoneMap . get ( "mobile" ) || "" ,
78
80
businessPhone : phoneMap . get ( "business" ) || "" ,
@@ -114,9 +116,11 @@ const EditContactTemplate = () => {
114
116
website : values . website ,
115
117
mailTip : values . mailTip ,
116
118
} ;
117
- } , ) ;
118
-
119
- const contactTemplate = Array . isArray ( contactTemplateInfo . data ) ? contactTemplateInfo . data [ 0 ] : contactTemplateInfo . data ;
119
+ } ) ;
120
+
121
+ const contactTemplate = Array . isArray ( contactTemplateInfo . data )
122
+ ? contactTemplateInfo . data [ 0 ]
123
+ : contactTemplateInfo . data ;
120
124
121
125
return (
122
126
< CippFormPage
@@ -129,10 +133,10 @@ const EditContactTemplate = () => {
129
133
data = { contactTemplate }
130
134
customDataformatter = { customDataFormatter }
131
135
>
132
- < ContactFormLayout
133
- formControl = { formControl }
134
- formType = "edit"
135
- />
136
+ { contactTemplateInfo . isLoading && < CippFormSkeleton layout = { [ 2 , 2 , 1 , 2 , 1 , 2 , 2 , 2 , 4 ] } /> }
137
+ { ! contactTemplateInfo . isLoading && (
138
+ < ContactFormLayout formControl = { formControl } formType = "edit" />
139
+ ) }
136
140
</ CippFormPage >
137
141
) ;
138
142
} ;
0 commit comments