From 8b0a1ec3a7d2cf2593ac7aff16c3624280d27ffa Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Mar 2026 07:19:09 +0000 Subject: [PATCH] =?UTF-8?q?feat(settings):=20add=20edit=20plan=20modal=20?= =?UTF-8?q?=E2=80=94=20name/type/speed/price=20inline=20edit=20(M9.4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(app)/settings/page.tsx | 85 ++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/app/(app)/settings/page.tsx b/app/(app)/settings/page.tsx index b637ddb..b5b7339 100644 --- a/app/(app)/settings/page.tsx +++ b/app/(app)/settings/page.tsx @@ -399,6 +399,8 @@ function PlansSettings() { const [speedUp, setSpeedUp] = useState(""); const [price, setPrice] = useState(""); const [description, setDescription] = useState(""); + const [editPlan, setEditPlan] = useState(null); + const [editForm, setEditForm] = useState({ name: "", type: "POSTPAID", speedDown: "", speedUp: "", price: "", description: "" }); const { data, isLoading, refetch } = useQuery({ queryKey: ["plans"], @@ -444,6 +446,38 @@ function PlansSettings() { onError: () => toast.error("Failed to update plan"), }); + const editPlanMutation = useMutation({ + mutationFn: async () => { + if (!editPlan) return; + await api.patch(`/api/v1/plans/${editPlan.id}`, { + name: editForm.name, + type: editForm.type, + speedDownMbps: parseInt(editForm.speedDown), + speedUpMbps: parseInt(editForm.speedUp), + monthlyPrice: parseFloat(editForm.price), + description: editForm.description || undefined, + }); + }, + onSuccess: () => { + toast.success("Plan updated"); + setEditPlan(null); + refetch(); + }, + onError: () => toast.error("Failed to update plan"), + }); + + function openEdit(p: Plan) { + setEditPlan(p); + setEditForm({ + name: p.name, + type: p.type, + speedDown: String(p.speedDownMbps), + speedUp: String(p.speedUpMbps), + price: String(Number(p.monthlyPrice)), + description: p.description ?? "", + }); + } + function resetAdd() { setPlanName(""); setPlanType("POSTPAID"); setSpeedDown(""); setSpeedUp(""); setPrice(""); setDescription(""); @@ -498,13 +532,22 @@ function PlansSettings() { - +
+ + +
)) @@ -514,6 +557,34 @@ function PlansSettings() { + {/* Edit Plan Modal */} + setEditPlan(null)} title="Edit Plan" className="max-w-lg"> +
{ e.preventDefault(); editPlanMutation.mutate(); }} className="space-y-4"> + setEditForm(f => ({ ...f, name: e.target.value }))} /> +
+ + +
+
+ setEditForm(f => ({ ...f, speedDown: e.target.value }))} /> + setEditForm(f => ({ ...f, speedUp: e.target.value }))} /> +
+ setEditForm(f => ({ ...f, price: e.target.value }))} /> + setEditForm(f => ({ ...f, description: e.target.value }))} /> +
+ + +
+
+
+ {/* Add Plan Modal */} { setShowAdd(false); resetAdd(); }} title="Add Plan" className="max-w-lg">
{ e.preventDefault(); addPlanMutation.mutate(); }} className="space-y-4">