diff --git a/vite/src/views/products/plan/PlanEditorView.tsx b/vite/src/views/products/plan/PlanEditorView.tsx index 41f9d7c34..84e746d6e 100644 --- a/vite/src/views/products/plan/PlanEditorView.tsx +++ b/vite/src/views/products/plan/PlanEditorView.tsx @@ -6,13 +6,13 @@ import { useProductChangedAlert } from "../product/hooks/useProductChangedAlert" import { useProductQuery } from "../product/hooks/useProductQuery"; import { ProductContext, useProductContext } from "../product/ProductContext"; import { ProductItemContext } from "../product/product-item/ProductItemContext"; -import ConfirmNewVersionDialog from "../product/versioning/ConfirmNewVersionDialog"; import { EditPlanFeatureSheet } from "./components/EditPlanFeatureSheet/EditPlanFeatureSheet"; import { EditPlanHeader } from "./components/EditPlanHeader"; import { EditPlanSheet } from "./components/EditPlanSheet"; import { ManagePlan } from "./components/ManagePlan"; import { SaveChangesBar } from "./components/SaveChangesBar"; import { usePlanData } from "./hooks/usePlanData"; +import ConfirmNewVersionDialog from "./versioning/ConfirmNewVersionDialog"; type Sheets = "edit-plan" | "edit-feature" | null; @@ -26,7 +26,7 @@ export default function PlanEditorView() { const { modal } = useProductChangedAlert({ hasChanges }); const [showNewVersionDialog, setShowNewVersionDialog] = useState(false); - const [sheet, setSheet] = useState(null); + const [sheet, setSheet] = useState("edit-plan"); const [editingState, setEditingState] = useState<{ type: "plan" | "feature" | null; id: string | null; @@ -62,6 +62,11 @@ export default function PlanEditorView() { { + // Reset editing state when new version is created + setEditingState({ type: null, id: null }); + setSheet("edit-plan"); + }} />
diff --git a/vite/src/views/products/plan/versioning/ConfirmNewVersionDialog.tsx b/vite/src/views/products/plan/versioning/ConfirmNewVersionDialog.tsx new file mode 100644 index 000000000..a9db9f924 --- /dev/null +++ b/vite/src/views/products/plan/versioning/ConfirmNewVersionDialog.tsx @@ -0,0 +1,89 @@ +import { useState } from "react"; +import { toast } from "sonner"; +import { Button } from "@/components/v2/buttons/Button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/v2/dialogs/Dialog"; +import { Input } from "@/components/v2/inputs/Input"; +import { useAxiosInstance } from "@/services/useAxiosInstance"; +import { useProductQuery } from "../../product/hooks/useProductQuery"; +import { useProductContext } from "../../product/ProductContext"; +import { updateProduct } from "../../product/utils/updateProduct"; + +export default function ConfirmNewVersionDialog({ + open, + setOpen, + onVersionCreated, +}: { + open: boolean; + setOpen: (open: boolean) => void; + onVersionCreated?: () => void; +}) { + const axiosInstance = useAxiosInstance(); + const { product } = useProductContext(); + const { refetch } = useProductQuery(); + + const [confirmText, setConfirmText] = useState(""); + const [isLoading, setIsLoading] = useState(false); + + const onClick = async () => { + if (confirmText !== product.id) { + toast.error("Confirmation text is incorrect"); + return; + } + + setIsLoading(true); + await updateProduct({ + axiosInstance, + product, + onSuccess: async () => { + await refetch(); + onVersionCreated?.(); // Reset editing state + }, + }); + setIsLoading(false); + setOpen(false); + // toast.success("New version created successfully"); + }; + + return ( + + + + + Create new version? + +

+ After creating a new version, it will be{" "} + + active immediately for new customers + + . You can migrate existing customers to the new version after. +

+

+ Type {product.id} to continue. +

+ setConfirmText(e.target.value)} + type="text" + placeholder={product.id} + className="w-full text-black" + /> +
+
+ + + +
+
+ ); +} diff --git a/vite/src/views/products/product/hooks/useProductQuery.tsx b/vite/src/views/products/product/hooks/useProductQuery.tsx index fa12cf5b6..212aa41a1 100644 --- a/vite/src/views/products/product/hooks/useProductQuery.tsx +++ b/vite/src/views/products/product/hooks/useProductQuery.tsx @@ -36,9 +36,12 @@ export const useProductQuery = () => { if (!productId) return null; const url = `/products/${productId}/data2`; - const queryParams = { - version: queryStates.version, - }; + const queryParams: { version?: number } = {}; + + // Only include version if it's explicitly set, otherwise fetch latest + if (queryStates.version) { + queryParams.version = queryStates.version; + } const { data } = await axiosInstance.get(url, { params: queryParams }); return data;