refactor: streamline modal close handlers and completion callbacks across various components

This commit is contained in:
Victor Santos
2025-10-31 18:43:34 -03:00
parent 7d8b28367e
commit b26fb73053
116 changed files with 1865 additions and 2949 deletions
@@ -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 (