update subscription plan fix
This commit is contained in:
parent
0945d85838
commit
b451f415db
2
.env
2
.env
|
|
@ -1,3 +1,3 @@
|
||||||
VITE_API_BASE_URL=https://api.yimaruacademy.com/api/v1
|
VITE_API_BASE_URL=https://api.yimaruacademy.com/api/v1
|
||||||
# VITE_API_BASE_URL=http://localhost:8432/api/v1
|
# VITE_API_BASE_URL=http://localhost:8432/api/v1
|
||||||
VITE_GOOGLE_CLIENT_ID=
|
VITE_GOOGLE_CLIENT_ID=
|
||||||
|
|
@ -114,7 +114,7 @@ export function CreateSubscriptionPlanDialog({
|
||||||
toast.success(res.message || "Subscription plan created successfully")
|
toast.success(res.message || "Subscription plan created successfully")
|
||||||
onCreated(res.data)
|
onCreated(res.data)
|
||||||
onOpenChange(false)
|
onOpenChange(false)
|
||||||
} catch {
|
} catch (err) {
|
||||||
notifyApiError(err, "Failed to create subscription plan.")
|
notifyApiError(err, "Failed to create subscription plan.")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,13 @@ function draftToPayload(draft: EditDraft): UpdateSubscriptionPlanPayload | null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mergePlanWithPayload(
|
||||||
|
plan: SubscriptionPlan,
|
||||||
|
payload: UpdateSubscriptionPlanPayload,
|
||||||
|
): SubscriptionPlan {
|
||||||
|
return { ...plan, ...payload }
|
||||||
|
}
|
||||||
|
|
||||||
type EditSubscriptionPlanDialogProps = {
|
type EditSubscriptionPlanDialogProps = {
|
||||||
plan: SubscriptionPlan | null
|
plan: SubscriptionPlan | null
|
||||||
open: boolean
|
open: boolean
|
||||||
|
|
@ -114,18 +121,15 @@ export function EditSubscriptionPlanDialog({
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
const res = await updateSubscriptionPlan(plan.id, payload)
|
const res = await updateSubscriptionPlan(plan.id, payload)
|
||||||
if (!res.data) {
|
const updated = res.data ?? mergePlanWithPayload(plan, payload)
|
||||||
toast.error("Plan was updated but the response could not be read.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
toast.success(res.message || "Subscription plan updated successfully")
|
toast.success(res.message || "Subscription plan updated successfully")
|
||||||
onUpdated({
|
onUpdated({
|
||||||
...res.data,
|
...updated,
|
||||||
category: res.data.category || plan.category,
|
category: updated.category || plan.category,
|
||||||
created_at: res.data.created_at || plan.created_at,
|
created_at: updated.created_at || plan.created_at,
|
||||||
})
|
})
|
||||||
onOpenChange(false)
|
onOpenChange(false)
|
||||||
} catch {
|
} catch (err) {
|
||||||
notifyApiError(err, "Failed to update subscription plan.")
|
notifyApiError(err, "Failed to update subscription plan.")
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user