@@ -15,29 +15,34 @@ export const showSidebox = ({ contact }) => {
1515 return contact ;
1616} ;
1717
18- export class TexterSideboxClass extends React . Component {
19- constructor ( props ) {
20- let customFields = props . contact . customFields ;
21- if ( typeof props . contact . customFields === "string" ) {
22- try {
23- customFields = JSON . parse ( props . contact . customFields || "{}" ) ;
24- } catch ( err ) {
25- // eslint-disable-next-line no-console
26- console . warn ( err ) ;
27- customFields = { } ;
28- }
18+ const parseCustomFields = customFields => {
19+ if ( typeof customFields === "string" ) {
20+ try {
21+ customFields = JSON . parse ( customFields || "{}" ) ;
22+ } catch ( err ) {
23+ // eslint-disable-next-line no-console
24+ console . warn ( err ) ;
25+ customFields = { } ;
2926 }
27+ }
28+ return customFields ;
29+ } ;
3030
31+ export class TexterSideboxClass extends React . Component {
32+ constructor ( props ) {
33+ let parsedCustomFields = parseCustomFields ( props . contact . customFields ) ;
3134 super ( props ) ;
3235 this . state = {
33- notes : customFields . notes || "" ,
36+ parsedCustomFields,
37+ notes : parsedCustomFields . notes || "" ,
3438 isSaving : false ,
3539 hasError : false
3640 } ;
3741 }
3842
3943 componentDidUpdate ( ) {
40- const { notes : contactNotes } = this . props . contact . customFields ;
44+ const { contact } = this . props ;
45+ const { notes : contactNotes } = parseCustomFields ( contact . customFields ) ;
4146 if ( this . state . isSaving && contactNotes === this . state . notes ) {
4247 this . setIsSaving ( false ) ;
4348 }
@@ -47,10 +52,11 @@ export class TexterSideboxClass extends React.Component {
4752
4853 debouncedUpdate = _ . debounce (
4954 async notes => {
55+ const { parsedCustomFields } = this . state ;
5056 const { contact, mutations } = this . props ;
5157 try {
5258 const customFields = {
53- ...contact . customFields ,
59+ ...parsedCustomFields ,
5460 notes
5561 } ;
5662 await mutations . updateContactCustomFields ( JSON . stringify ( customFields ) ) ;
0 commit comments