@@ -130,7 +130,7 @@ export default function DashboardPage() {
130130 } ) ) ,
131131 }
132132
133- const data = {
133+ const baseData = {
134134 profileName,
135135 profileDescription,
136136 logos : {
@@ -147,26 +147,28 @@ export default function DashboardPage() {
147147 streamId : selectedProfileType ?. profileDetails . streamId ,
148148 }
149149
150+ const dataForStorage = id ? { ...baseData , id } : baseData
151+
150152 const token = localStorage . getItem ( "stytchToken" )
151153
152154 if ( ! token ) {
153- localStorage . setItem ( "configData" , JSON . stringify ( data ) )
155+ localStorage . setItem ( "configData" , JSON . stringify ( dataForStorage ) )
154156 router . push ( "/auth" )
155157 return
156158 }
157159
158- let response
160+ let response ;
159161
160162 if ( ! id ) {
161- response = await axios . post ( `${ process . env . NEXT_PUBLIC_DASHBOARD_API } /crm/client-app` , data , {
163+ response = await axios . post ( `${ process . env . NEXT_PUBLIC_DASHBOARD_API } /crm/client-app` , baseData , {
162164 headers : {
163165 "Content-Type" : "application/json" ,
164166 Authorization : `Bearer ${ token } ` ,
165167 } ,
166168 validateStatus : ( ) => true ,
167169 } )
168170 } else {
169- response = await axios . put ( `${ process . env . NEXT_PUBLIC_DASHBOARD_API } /crm/client-app/${ id } ` , data , {
171+ response = await axios . put ( `${ process . env . NEXT_PUBLIC_DASHBOARD_API } /crm/client-app/${ id } ` , baseData , {
170172 headers : {
171173 "Content-Type" : "application/json" ,
172174 Authorization : `Bearer ${ token } ` ,
@@ -183,7 +185,10 @@ export default function DashboardPage() {
183185 router . push ( "/dashboard" )
184186 } else if ( response . status === 401 ) {
185187 localStorage . clear ( )
186- localStorage . setItem ( "configData" , JSON . stringify ( data ) )
188+ localStorage . setItem ( "configData" , JSON . stringify ( dataForStorage ) )
189+ if ( id ) {
190+ localStorage . setItem ( "editMode" , 'true' )
191+ }
187192 router . push ( "/auth" )
188193 } else {
189194 alert ( "Failed to create client app." )
@@ -224,6 +229,8 @@ export default function DashboardPage() {
224229
225230 useEffect ( ( ) => {
226231 if ( id ) {
232+ localStorage . setItem ( "editMode" , 'true' )
233+ console . log ( "App" , app )
227234 setCustomizationData ( {
228235 general : {
229236 theme : "light" ,
@@ -233,8 +240,8 @@ export default function DashboardPage() {
233240 } ,
234241 } ,
235242 authOptions : {
236- email : app ?. authentication . email ?? true ,
237- gmail : app ?. authentication . gmail ?? true ,
243+ email : app ?. authentication ? .email ?? true ,
244+ gmail : app ?. authentication ? .gmail ?? true ,
238245 metamask : app ?. authentication . wallet ?? true ,
239246 } ,
240247 } ) ;
@@ -284,6 +291,8 @@ export default function DashboardPage() {
284291 setAppName ( app ?. appName || "<app_name_here>" ) ;
285292 setUrls ( Array . isArray ( app ?. domains ) ? app . domains : JSON . parse ( app ?. domains || "[]" ) ) ;
286293 setShowRoulette ( app ?. showRoulette || true ) ;
294+ } else {
295+ localStorage . removeItem ( "editMode" )
287296 }
288297 } , [ id , app ] ) ;
289298
0 commit comments