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=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")
|
||||
onCreated(res.data)
|
||||
onOpenChange(false)
|
||||
} catch {
|
||||
} catch (err) {
|
||||
notifyApiError(err, "Failed to create subscription plan.")
|
||||
} finally {
|
||||
setSaving(false)
|
||||
|
|
|
|||
|
|
@ -74,6 +74,13 @@ function draftToPayload(draft: EditDraft): UpdateSubscriptionPlanPayload | null
|
|||
}
|
||||
}
|
||||
|
||||
function mergePlanWithPayload(
|
||||
plan: SubscriptionPlan,
|
||||
payload: UpdateSubscriptionPlanPayload,
|
||||
): SubscriptionPlan {
|
||||
return { ...plan, ...payload }
|
||||
}
|
||||
|
||||
type EditSubscriptionPlanDialogProps = {
|
||||
plan: SubscriptionPlan | null
|
||||
open: boolean
|
||||
|
|
@ -114,18 +121,15 @@ export function EditSubscriptionPlanDialog({
|
|||
setSaving(true)
|
||||
try {
|
||||
const res = await updateSubscriptionPlan(plan.id, payload)
|
||||
if (!res.data) {
|
||||
toast.error("Plan was updated but the response could not be read.")
|
||||
return
|
||||
}
|
||||
const updated = res.data ?? mergePlanWithPayload(plan, payload)
|
||||
toast.success(res.message || "Subscription plan updated successfully")
|
||||
onUpdated({
|
||||
...res.data,
|
||||
category: res.data.category || plan.category,
|
||||
created_at: res.data.created_at || plan.created_at,
|
||||
...updated,
|
||||
category: updated.category || plan.category,
|
||||
created_at: updated.created_at || plan.created_at,
|
||||
})
|
||||
onOpenChange(false)
|
||||
} catch {
|
||||
} catch (err) {
|
||||
notifyApiError(err, "Failed to update subscription plan.")
|
||||
} finally {
|
||||
setSaving(false)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user