refactor: simplify authentication form submission logic across multiple identity sections

This commit is contained in:
Victor Santos
2025-10-31 19:23:32 -03:00
parent b26fb73053
commit eba04e4278
12 changed files with 468 additions and 567 deletions
@@ -137,7 +137,6 @@ export const IdentityAliCloudAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try {
if (!identityId) return; if (!identityId) return;
if (data) { if (data) {
@@ -170,12 +169,6 @@ export const IdentityAliCloudAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
return ( return (
@@ -103,7 +103,6 @@ export const IdentityAuthTemplateModal = ({ popUp, handlePopUpToggle }: Props) =
const selectedMethod = watch("method"); const selectedMethod = watch("method");
const onFormSubmit = async (data: FormData) => { const onFormSubmit = async (data: FormData) => {
try {
if (isEdit && template) { if (isEdit && template) {
await updateTemplate({ await updateTemplate({
templateId: template.id, templateId: template.id,
@@ -142,17 +141,6 @@ export const IdentityAuthTemplateModal = ({ popUp, handlePopUpToggle }: Props) =
handlePopUpToggle(isEdit ? "editTemplate" : "createTemplate", false); handlePopUpToggle(isEdit ? "editTemplate" : "createTemplate", false);
reset(); reset();
} catch (err) {
console.error(err);
const error = err as any;
const text =
error?.response?.data?.message ?? `Failed to ${isEdit ? "update" : "create"} auth template`;
createNotification({
text,
type: "error"
});
}
}; };
const handleClose = () => { const handleClose = () => {
@@ -147,7 +147,6 @@ export const IdentityAwsAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try {
if (!identityId) return; if (!identityId) return;
if (data) { if (data) {
@@ -184,12 +183,6 @@ export const IdentityAwsAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
return ( return (
@@ -143,7 +143,6 @@ export const IdentityAzureAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try {
if (!identityId) return; if (!identityId) return;
if (data) { if (data) {
@@ -180,12 +179,6 @@ export const IdentityAzureAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
return ( return (
@@ -152,7 +152,6 @@ export const IdentityGcpAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try {
if (!identityId) return; if (!identityId) return;
if (data) { if (data) {
@@ -191,12 +190,6 @@ export const IdentityGcpAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
return ( return (
@@ -217,7 +217,6 @@ export const IdentityJwtAuthForm = ({
boundClaims, boundClaims,
boundSubject boundSubject
}: FormData) => { }: FormData) => {
try {
if (!identityId) { if (!identityId) {
return; return;
} }
@@ -266,12 +265,6 @@ export const IdentityJwtAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
return ( return (
@@ -311,7 +311,6 @@ export const IdentityKubernetesAuthForm = ({
tokenReviewMode, tokenReviewMode,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try {
if (!identityId) return; if (!identityId) return;
if (data) { if (data) {
@@ -370,12 +369,6 @@ export const IdentityKubernetesAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
const tokenReviewMode = watch("tokenReviewMode"); const tokenReviewMode = watch("tokenReviewMode");
@@ -316,7 +316,6 @@ export const IdentityLdapAuthForm = ({
}, [subscription, handlePopUpOpen, handlePopUpToggle]); }, [subscription, handlePopUpOpen, handlePopUpToggle]);
const onFormSubmit = async (formData: FormData) => { const onFormSubmit = async (formData: FormData) => {
try {
if (!identityId) return; if (!identityId) return;
const { const {
@@ -387,12 +386,6 @@ export const IdentityLdapAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
return ( return (
@@ -42,7 +42,6 @@ export const IdentityLinkForm = ({ onClose }: Props) => {
}); });
const onFormSubmit = async ({ identity, role }: FormData) => { const onFormSubmit = async ({ identity, role }: FormData) => {
try {
await createMutateAsync({ await createMutateAsync({
identityId: identity.id, identityId: identity.id,
roles: [{ role: role.slug, isTemporary: false }] roles: [{ role: role.slug, isTemporary: false }]
@@ -57,16 +56,6 @@ export const IdentityLinkForm = ({ onClose }: Props) => {
identityId: identity.id identityId: identity.id
} }
}); });
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to link identity";
createNotification({
text,
type: "error"
});
}
}; };
return ( return (
@@ -108,7 +108,6 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [popUp?.identity?.data, roles]); }, [popUp?.identity?.data, roles]);
const onFormSubmit = async ({ name, role, metadata, hasDeleteProtection }: FormData) => { const onFormSubmit = async ({ name, role, metadata, hasDeleteProtection }: FormData) => {
try {
const identity = popUp?.identity?.data as { const identity = popUp?.identity?.data as {
identityId: string; identityId: string;
name: string; name: string;
@@ -171,18 +170,6 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
}); });
reset(); reset();
} catch (err) {
console.error(err);
const error = err as any;
const text =
error?.response?.data?.message ??
`Failed to ${popUp?.identity?.data ? "update" : "create"} identity`;
createNotification({
text,
type: "error"
});
}
}; };
return ( return (
@@ -149,7 +149,6 @@ export const IdentityOciAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try {
if (!identityId) return; if (!identityId) return;
if (data) { if (data) {
@@ -184,12 +183,6 @@ export const IdentityOciAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
return ( return (
@@ -201,7 +201,6 @@ export const IdentityOidcAuthForm = ({
claimMetadataMapping, claimMetadataMapping,
boundSubject boundSubject
}: FormData) => { }: FormData) => {
try {
if (!identityId) { if (!identityId) {
return; return;
} }
@@ -252,12 +251,6 @@ export const IdentityOidcAuthForm = ({
}); });
reset(); reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
}; };
return ( return (