mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-21 13:06:59 +02:00
enable editing resource policy niceID
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
} from "@app/components/Settings";
|
} from "@app/components/Settings";
|
||||||
|
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { useOrgContext } from "@app/hooks/useOrgContext";
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
@@ -40,21 +41,28 @@ import { useForm } from "react-hook-form";
|
|||||||
|
|
||||||
// ─── PolicyNameSection ──────────────────────────────────────────────────
|
// ─── PolicyNameSection ──────────────────────────────────────────────────
|
||||||
|
|
||||||
export function EditPolicyNameSectionForm({ readonly }: { readonly?: boolean }) {
|
const PolicyNameFormSchema = z.object({
|
||||||
|
name: z.string(),
|
||||||
|
niceId: z.string().min(1).max(255).optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
export function EditPolicyNameSectionForm({
|
||||||
|
readonly
|
||||||
|
}: {
|
||||||
|
readonly?: boolean;
|
||||||
|
}) {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { org } = useOrgContext();
|
||||||
|
|
||||||
const { policy } = useResourcePolicyContext();
|
const { policy, updatePolicy } = useResourcePolicyContext();
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
resolver: zodResolver(
|
resolver: zodResolver(PolicyNameFormSchema),
|
||||||
z.object({
|
|
||||||
name: z.string()
|
|
||||||
})
|
|
||||||
),
|
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: policy.name
|
name: policy.name,
|
||||||
|
niceId: policy.niceId || ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -73,7 +81,8 @@ export function EditPolicyNameSectionForm({ readonly }: { readonly?: boolean })
|
|||||||
.put<AxiosResponse<ResourcePolicy>>(
|
.put<AxiosResponse<ResourcePolicy>>(
|
||||||
`/resource-policy/${policy.resourcePolicyId}`,
|
`/resource-policy/${policy.resourcePolicyId}`,
|
||||||
{
|
{
|
||||||
name: payload.name
|
name: payload.name,
|
||||||
|
niceId: payload.niceId
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
@@ -88,10 +97,22 @@ export function EditPolicyNameSectionForm({ readonly }: { readonly?: boolean })
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (res && res.status === 200) {
|
if (res && res.status === 200) {
|
||||||
|
updatePolicy({
|
||||||
|
name: payload.name,
|
||||||
|
niceId: payload.niceId
|
||||||
|
});
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("success"),
|
title: t("success"),
|
||||||
description: t("policyUpdatedSuccess")
|
description: t("policyUpdatedSuccess")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (payload.niceId && payload.niceId !== policy.niceId) {
|
||||||
|
router.replace(
|
||||||
|
`/${org.org.orgId}/settings/policies/resource/${payload.niceId}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
router.refresh();
|
router.refresh();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -136,6 +157,26 @@ export function EditPolicyNameSectionForm({ readonly }: { readonly?: boolean })
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="niceId"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t("identifier")}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
disabled={readonly}
|
||||||
|
placeholder={t(
|
||||||
|
"enterIdentifier"
|
||||||
|
)}
|
||||||
|
className="flex-1"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</SettingsSectionForm>
|
</SettingsSectionForm>
|
||||||
</SettingsSectionBody>
|
</SettingsSectionBody>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user