mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 20:27:12 +00:00
greptile review fixes
This commit is contained in:
+22
-5
@@ -3,6 +3,8 @@ import { useEffect, useState } from "react";
|
|||||||
import { Switch } from "@app/components/v2";
|
import { Switch } from "@app/components/v2";
|
||||||
import { useOrganization } from "@app/context";
|
import { useOrganization } from "@app/context";
|
||||||
import { useUpdateOrg } from "@app/hooks/api";
|
import { useUpdateOrg } from "@app/hooks/api";
|
||||||
|
import axios from "axios";
|
||||||
|
import { createNotification } from "@app/components/notifications";
|
||||||
|
|
||||||
export const OrgProductSelectSection = () => {
|
export const OrgProductSelectSection = () => {
|
||||||
const [toggledProducts, setToggledProducts] = useState<{
|
const [toggledProducts, setToggledProducts] = useState<{
|
||||||
@@ -34,6 +36,8 @@ export const OrgProductSelectSection = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const { currentOrg } = useOrganization();
|
const { currentOrg } = useOrganization();
|
||||||
const { mutateAsync } = useUpdateOrg();
|
const { mutateAsync } = useUpdateOrg();
|
||||||
|
|
||||||
@@ -49,17 +53,29 @@ export const OrgProductSelectSection = () => {
|
|||||||
}, [currentOrg]);
|
}, [currentOrg]);
|
||||||
|
|
||||||
const onProductToggle = async (value: boolean, key: string) => {
|
const onProductToggle = async (value: boolean, key: string) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
setToggledProducts((products) => ({
|
setToggledProducts((products) => ({
|
||||||
...products,
|
...products,
|
||||||
[key]: { ...products[key], enabled: value }
|
[key]: { ...products[key], enabled: value }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await mutateAsync({
|
||||||
|
orgId: currentOrg.id,
|
||||||
|
[key]: value
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (axios.isAxiosError(e)) {
|
||||||
|
const { message = "Something went wrong" } = e.response?.data as { message: string };
|
||||||
|
createNotification({
|
||||||
|
type: "error",
|
||||||
|
text: message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update backend
|
setIsLoading(false);
|
||||||
await mutateAsync({
|
|
||||||
orgId: currentOrg.id,
|
|
||||||
[key]: value
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -74,6 +90,7 @@ export const OrgProductSelectSection = () => {
|
|||||||
<Switch
|
<Switch
|
||||||
key={key}
|
key={key}
|
||||||
id={`enable-${key}`}
|
id={`enable-${key}`}
|
||||||
|
isDisabled={isLoading}
|
||||||
onCheckedChange={(value) => onProductToggle(value, key)}
|
onCheckedChange={(value) => onProductToggle(value, key)}
|
||||||
isChecked={product.enabled}
|
isChecked={product.enabled}
|
||||||
className="ml-0"
|
className="ml-0"
|
||||||
|
|||||||
Reference in New Issue
Block a user