mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-21 14:28:09 +00:00
refactor: streamline modal close handlers and completion callbacks across various components
This commit is contained in:
+22
-40
@@ -38,27 +38,18 @@ const CreateForm = ({
|
||||
const onSubmit = async (
|
||||
formData: DiscriminativePick<TPamAccount, "name" | "description" | "credentials">
|
||||
) => {
|
||||
try {
|
||||
const account = await createPamAccount.mutateAsync({
|
||||
...formData,
|
||||
folderId,
|
||||
resourceId,
|
||||
resourceType,
|
||||
projectId
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully created account",
|
||||
type: "success"
|
||||
});
|
||||
onComplete(account);
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
title: "Failed to create account",
|
||||
text: err.message,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
const account = await createPamAccount.mutateAsync({
|
||||
...formData,
|
||||
folderId,
|
||||
resourceId,
|
||||
resourceType,
|
||||
projectId
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully created account",
|
||||
type: "success"
|
||||
});
|
||||
onComplete(account);
|
||||
};
|
||||
|
||||
switch (resourceType) {
|
||||
@@ -85,25 +76,16 @@ const UpdateForm = ({ account, onComplete }: UpdateFormProps) => {
|
||||
const onSubmit = async (
|
||||
formData: DiscriminativePick<TPamAccount, "name" | "description" | "credentials">
|
||||
) => {
|
||||
try {
|
||||
const updatedAccount = await updatePamAccount.mutateAsync({
|
||||
accountId: account.id,
|
||||
resourceType: account.resource.resourceType,
|
||||
...formData
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully updated account",
|
||||
type: "success"
|
||||
});
|
||||
onComplete(updatedAccount);
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
title: "Failed to update account",
|
||||
text: err.message,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
const updatedAccount = await updatePamAccount.mutateAsync({
|
||||
accountId: account.id,
|
||||
resourceType: account.resource.resourceType,
|
||||
...formData
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully updated account",
|
||||
type: "success"
|
||||
});
|
||||
onComplete(updatedAccount);
|
||||
};
|
||||
|
||||
switch (account.resource.resourceType) {
|
||||
|
||||
@@ -17,25 +17,16 @@ export const PamAddFolderModal = ({ isOpen, onOpenChange, projectId, currentFold
|
||||
console.log({ currentFolderId });
|
||||
|
||||
const onSubmit = async (formData: Pick<TPamFolder, "name" | "description">) => {
|
||||
try {
|
||||
await createPamFolder.mutateAsync({
|
||||
...formData,
|
||||
parentId: currentFolderId,
|
||||
projectId
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully created folder",
|
||||
type: "success"
|
||||
});
|
||||
onOpenChange(false);
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
title: "Failed to create folder",
|
||||
text: err.message,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
await createPamFolder.mutateAsync({
|
||||
...formData,
|
||||
parentId: currentFolderId,
|
||||
projectId
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully created folder",
|
||||
type: "success"
|
||||
});
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -20,25 +20,17 @@ export const PamDeleteAccountModal = ({ isOpen, onOpenChange, account }: Props)
|
||||
} = account;
|
||||
|
||||
const handleDelete = async () => {
|
||||
try {
|
||||
await deletePamAccount.mutateAsync({
|
||||
accountId,
|
||||
resourceType
|
||||
});
|
||||
await deletePamAccount.mutateAsync({
|
||||
accountId,
|
||||
resourceType
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: "Successfully deleted account",
|
||||
type: "success"
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully deleted account",
|
||||
type: "success"
|
||||
});
|
||||
|
||||
onOpenChange(false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
text: "Failed to delete account",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -16,24 +16,16 @@ export const PamDeleteFolderModal = ({ isOpen, onOpenChange, folder }: Props) =>
|
||||
const { id: folderId, name } = folder;
|
||||
|
||||
const handleDelete = async () => {
|
||||
try {
|
||||
await deletePamFolder.mutateAsync({
|
||||
folderId
|
||||
});
|
||||
await deletePamFolder.mutateAsync({
|
||||
folderId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: "Successfully deleted folder",
|
||||
type: "success"
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully deleted folder",
|
||||
type: "success"
|
||||
});
|
||||
|
||||
onOpenChange(false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
text: "Failed to delete folder",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -16,24 +16,15 @@ export const PamUpdateFolderModal = ({ isOpen, onOpenChange, folder }: Props) =>
|
||||
if (!folder) return null;
|
||||
|
||||
const onSubmit = async (formData: Pick<TPamFolder, "name" | "description">) => {
|
||||
try {
|
||||
await updatePamFolder.mutateAsync({
|
||||
...formData,
|
||||
folderId: folder.id
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully updated folder",
|
||||
type: "success"
|
||||
});
|
||||
onOpenChange(false);
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
title: "Failed to updated folder",
|
||||
text: err.message,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
await updatePamFolder.mutateAsync({
|
||||
...formData,
|
||||
folderId: folder.id
|
||||
});
|
||||
createNotification({
|
||||
text: "Successfully updated folder",
|
||||
type: "success"
|
||||
});
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user