Adjust test mode toggles for submitting product import
This commit is contained in:
@@ -45,15 +45,8 @@ export const ImageUploadStep = ({
|
|||||||
const fileInputRefs = useRef<{ [key: number]: React.RefObject<HTMLInputElement> }>({});
|
const fileInputRefs = useRef<{ [key: number]: React.RefObject<HTMLInputElement> }>({});
|
||||||
const { user } = useContext(AuthContext);
|
const { user } = useContext(AuthContext);
|
||||||
const hasDebugPermission = Boolean(user?.is_admin || user?.permissions?.includes("admin:debug"));
|
const hasDebugPermission = Boolean(user?.is_admin || user?.permissions?.includes("admin:debug"));
|
||||||
const [targetEnvironment, setTargetEnvironment] = useState<SubmitOptions["targetEnvironment"]>(
|
const [targetEnvironment, setTargetEnvironment] = useState<SubmitOptions["targetEnvironment"]>("prod");
|
||||||
hasDebugPermission ? "dev" : "prod"
|
const [useTestDataSource, setUseTestDataSource] = useState<boolean>(false);
|
||||||
);
|
|
||||||
const [useTestDataSource, setUseTestDataSource] = useState<boolean>(hasDebugPermission);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setTargetEnvironment(hasDebugPermission ? "dev" : "prod");
|
|
||||||
setUseTestDataSource(hasDebugPermission);
|
|
||||||
}, [hasDebugPermission]);
|
|
||||||
|
|
||||||
// Use our hook for product images initialization
|
// Use our hook for product images initialization
|
||||||
const { productImages, setProductImages, getFullImageUrl } = useProductImagesInit(data);
|
const { productImages, setProductImages, getFullImageUrl } = useProductImagesInit(data);
|
||||||
@@ -302,45 +295,34 @@ export const ImageUploadStep = ({
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-1 flex-wrap items-center justify-end gap-6">
|
<div className="flex flex-1 flex-wrap items-center justify-end gap-6">
|
||||||
<div className="flex flex-col gap-3 text-sm">
|
{hasDebugPermission && (
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex gap-4 text-sm">
|
||||||
<Switch
|
<div className="flex items-center gap-1">
|
||||||
id="product-import-api-environment"
|
<Switch
|
||||||
checked={targetEnvironment === "dev"}
|
id="product-import-api-environment"
|
||||||
disabled={!hasDebugPermission}
|
checked={targetEnvironment === "dev"}
|
||||||
onCheckedChange={(checked) => setTargetEnvironment(checked ? "dev" : "prod")}
|
onCheckedChange={(checked) => setTargetEnvironment(checked ? "dev" : "prod")}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="product-import-api-environment" className="text-sm font-medium">
|
<Label htmlFor="product-import-api-environment" className="text-sm font-medium">
|
||||||
Use development backend
|
Use test API
|
||||||
</Label>
|
</Label>
|
||||||
<p className="text-xs text-muted-foreground">
|
</div>
|
||||||
{targetEnvironment === "dev"
|
</div>
|
||||||
? "work-test-backend.acherryontop.com"
|
<div className="flex items-center gap-1">
|
||||||
: "backend.acherryontop.com"}
|
<Switch
|
||||||
</p>
|
id="product-import-api-test-data"
|
||||||
|
checked={useTestDataSource}
|
||||||
|
onCheckedChange={(checked) => setUseTestDataSource(checked)}
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="product-import-api-test-data" className="text-sm font-medium">
|
||||||
|
Use test database
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
)}
|
||||||
<Switch
|
|
||||||
id="product-import-api-test-data"
|
|
||||||
checked={useTestDataSource}
|
|
||||||
disabled={!hasDebugPermission}
|
|
||||||
onCheckedChange={(checked) => setUseTestDataSource(checked)}
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="product-import-api-test-data" className="text-sm font-medium">
|
|
||||||
Use test data source
|
|
||||||
</Label>
|
|
||||||
<p className="text-xs text-muted-foreground">Submit to the testing database</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{!hasDebugPermission && (
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Requires admin:debug permission to change
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<Button
|
<Button
|
||||||
className="min-w-[140px]"
|
className="min-w-[140px]"
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
|
|||||||
Reference in New Issue
Block a user