Skip to content

Commit 400eb95

Browse files
ZabeehUllahmujtabaidrees94
authored andcommitted
fix: UI bugs in edit flow
1 parent 70c0e98 commit 400eb95

5 files changed

Lines changed: 58 additions & 36 deletions

File tree

app/auth/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function AuthPage() {
1616
const [website, setWebsite] = useState("")
1717
const [email, setEmail] = useState("")
1818
const [errors, setErrors] = useState<{ [key: string]: string }>({})
19-
const [isLoading, setIsLoading] = useState(true) // Added loading state
19+
const [isLoading, setIsLoading] = useState(false) // Added loading state
2020
const [stytchToken, setStytchToken] = useState<string | null>(null);
2121
const router = useRouter()
2222

app/dashboard/page.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,13 @@ export default function DashboardPage() {
107107
useEffect(() => {
108108
getClientApps()
109109
hideDashboard()
110+
localStorage.removeItem("editMode")
110111
}, [])
111112

112113
const onEdit = (app: ClientApp) => {
113114
setApp(app)
114115
router.push(`/?id=${app.id}`)
115116
}
116-
117-
118117

119118
if (isLoading) {
120119
return (

app/otp/page.tsx

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,47 @@ export default function OTPPage() {
7070
}
7171

7272
const data = localStorage.getItem("configData");
73+
const isEditMode = localStorage.getItem("editMode");
74+
7375
const onboardingConfig = data ? JSON.parse(data) : null;
76+
const editMode = isEditMode ? JSON.parse(isEditMode) : null;
77+
78+
const { id, ...payload } = onboardingConfig;
7479

7580
const newData = {
76-
...onboardingConfig,
81+
...payload,
7782
clientId: client.id
7883
}
7984

85+
let response1;
86+
8087
// Create client app
81-
const response1 = await axios.post(
82-
`${process.env.NEXT_PUBLIC_DASHBOARD_API}/crm/client-app`,
83-
newData,
84-
{
85-
headers: {
86-
"Content-Type": "application/json",
87-
"Authorization": `Bearer ${response.data.stytchToken}`,
88-
},
89-
validateStatus: () => true,
90-
}
91-
);
88+
if(!editMode){
89+
response1 = await axios.post(
90+
`${process.env.NEXT_PUBLIC_DASHBOARD_API}/crm/client-app`,
91+
newData,
92+
{
93+
headers: {
94+
"Content-Type": "application/json",
95+
"Authorization": `Bearer ${response.data.stytchToken}`,
96+
},
97+
validateStatus: () => true,
98+
}
99+
);
100+
}else{
101+
response1 = await axios.put(
102+
`${process.env.NEXT_PUBLIC_DASHBOARD_API}/crm/client-app/${id}`,
103+
newData,
104+
{
105+
headers: {
106+
"Content-Type": "application/json",
107+
"Authorization": `Bearer ${response.data.stytchToken}`,
108+
},
109+
validateStatus: () => true,
110+
}
111+
);
112+
}
113+
92114

93115
if (response1.status === 200) {
94116
// Save credentials to context
@@ -111,9 +133,8 @@ export default function OTPPage() {
111133
} catch (error) {
112134
console.error("Error during OTP verification:", error);
113135
setError("An error occurred. Please try again.");
114-
} finally {
115-
setIsLoading(false); // Set loading to false after request completes
116-
}
136+
setIsLoading(false)
137+
}
117138

118139
}
119140

app/page.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

components/WidgetCard.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,6 @@ export default function WidgetCard({
365365
// Convert file to base64
366366
const base64String = await convertToBase64(file)
367367
setUploadedFile((prev) => ({ ...prev, [mode]: file }))
368-
setApp((prev) => ({
369-
...prev,
370-
logos: {
371-
...prev.logos,
372-
[mode]: base64String,
373-
},
374-
}))
375368
setCustomizationData((prev) => ({
376369
...prev,
377370
general: {
@@ -1270,20 +1263,20 @@ export default function WidgetCard({
12701263

12711264
{/* Footer always at the bottom */}
12721265
<div className="mt-auto pt-10 flex justify-end gap-2">
1273-
<Button
1266+
{!id && <Button
12741267
variant="outline"
12751268
className="text-gray-700 border-gray-300 hover:bg-gray-100"
12761269
onClick={saveConfigForLater}
12771270
disabled={!hasUserEnteredData()}
12781271
>
12791272
Save config for later
1280-
</Button>
1273+
</Button>}
12811274
<Button
12821275
className="bg-emerald-500 hover:bg-emerald-600 text-white flex items-center gap-1"
12831276
onClick={handleFinishSetupProp}
12841277
disabled={isButtonDisabled()}
12851278
>
1286-
Finish Setup <ArrowRight className="h-4 w-4" />
1279+
{id ? 'Update Config' : 'Finish Setup'} <ArrowRight className="h-4 w-4" />
12871280
</Button>
12881281
</div>
12891282
</div>

0 commit comments

Comments
 (0)