🚧 auth methods

This commit is contained in:
Fred KISSIE
2026-03-03 02:11:05 +01:00
parent 5c280b024e
commit 8a54fb7f23

View File

@@ -281,8 +281,8 @@ export function EditPolicyForm({ hidePolicyNameForm }: EditPolicyFormProps) {
allUsers={allUsers} allUsers={allUsers}
allIdps={allIdps} allIdps={allIdps}
/> />
<PolicyAuthMethodsSection />
{/* {/*
<PolicyAuthMethodsSection form={form} />
<PolicyOtpEmailSection <PolicyOtpEmailSection
form={form} form={form}
emailEnabled={env.email.emailEnabled} emailEnabled={env.email.emailEnabled}
@@ -429,8 +429,6 @@ export function PolicyUsersRolesSection({
const api = createApiClient(useEnvContext()); const api = createApiClient(useEnvContext());
console.log({ policy });
const form = useForm({ const form = useForm({
resolver: zodResolver( resolver: zodResolver(
createPolicySchema.pick({ createPolicySchema.pick({
@@ -736,15 +734,24 @@ const setHeaderAuthSchema = z.object({
extendedCompatibility: z.boolean() extendedCompatibility: z.boolean()
}); });
type PolicyAuthMethodsSectionProps = { export function PolicyAuthMethodsSection() {
form: UseFormReturn<PolicyFormValues, any, any>; const { policy } = useResourcePolicyContext();
};
const api = createApiClient(useEnvContext());
const form = useForm({
resolver: zodResolver(
createPolicySchema.pick({
password: true,
pincode: true,
headerAuth: true
})
),
defaultValues: {}
});
export function PolicyAuthMethodsSection({
form
}: PolicyAuthMethodsSectionProps) {
const t = useTranslations(); const t = useTranslations();
const [isOpen, setIsOpen] = useState(false); const [isExpanded, setIsExpanded] = useState(false);
const [isSetPasswordOpen, setIsSetPasswordOpen] = useState(false); const [isSetPasswordOpen, setIsSetPasswordOpen] = useState(false);
const [isSetPincodeOpen, setIsSetPincodeOpen] = useState(false); const [isSetPincodeOpen, setIsSetPincodeOpen] = useState(false);
const [isSetHeaderAuthOpen, setIsSetHeaderAuthOpen] = useState(false); const [isSetHeaderAuthOpen, setIsSetHeaderAuthOpen] = useState(false);
@@ -768,7 +775,18 @@ export function PolicyAuthMethodsSection({
defaultValues: { user: "", password: "", extendedCompatibility: true } defaultValues: { user: "", password: "", extendedCompatibility: true }
}); });
if (!isOpen) { const [, formAction, isSubmitting] = useActionState(onSubmit, null);
async function onSubmit() {
const isValid = await form.trigger();
if (!isValid) return;
const payload = form.getValues();
console.log({ payload });
}
if (!isExpanded) {
return ( return (
<SettingsSection> <SettingsSection>
<SettingsSectionHeader> <SettingsSectionHeader>
@@ -783,7 +801,7 @@ export function PolicyAuthMethodsSection({
<Button <Button
type="button" type="button"
variant="outline" variant="outline"
onClick={() => setIsOpen(true)} onClick={() => setIsExpanded(true)}
> >
<Plus className="mr-2 h-4 w-4" /> <Plus className="mr-2 h-4 w-4" />
{t("resourcePolicyAuthMethodAdd")} {t("resourcePolicyAuthMethodAdd")}
@@ -1050,6 +1068,8 @@ export function PolicyAuthMethodsSection({
</CredenzaContent> </CredenzaContent>
</Credenza> </Credenza>
<Form {...form}>
<form action={() => {}}>
<SettingsSection> <SettingsSection>
<SettingsSectionHeader> <SettingsSectionHeader>
<SettingsSectionTitle> <SettingsSectionTitle>
@@ -1081,8 +1101,13 @@ export function PolicyAuthMethodsSection({
size="sm" size="sm"
onClick={ onClick={
password password
? () => form.setValue("password", null) ? () =>
: () => setIsSetPasswordOpen(true) form.setValue(
"password",
null
)
: () =>
setIsSetPasswordOpen(true)
} }
> >
{password {password
@@ -1111,11 +1136,18 @@ export function PolicyAuthMethodsSection({
size="sm" size="sm"
onClick={ onClick={
pincode pincode
? () => form.setValue("pincode", null) ? () =>
: () => setIsSetPincodeOpen(true) form.setValue(
"pincode",
null
)
: () =>
setIsSetPincodeOpen(true)
} }
> >
{pincode ? t("pincodeRemove") : t("pincodeAdd")} {pincode
? t("pincodeRemove")
: t("pincodeAdd")}
</Button> </Button>
</div> </div>
@@ -1142,8 +1174,14 @@ export function PolicyAuthMethodsSection({
onClick={ onClick={
headerAuth headerAuth
? () => ? () =>
form.setValue("headerAuth", null) form.setValue(
: () => setIsSetHeaderAuthOpen(true) "headerAuth",
null
)
: () =>
setIsSetHeaderAuthOpen(
true
)
} }
> >
{headerAuth {headerAuth
@@ -1153,7 +1191,19 @@ export function PolicyAuthMethodsSection({
</div> </div>
</SettingsSectionForm> </SettingsSectionForm>
</SettingsSectionBody> </SettingsSectionBody>
<div className="flex py-6 justify-end">
<Button
type="submit"
loading={isSubmitting}
disabled={isSubmitting}
>
{t("saveSettings")}
</Button>
</div>
</SettingsSection> </SettingsSection>
</form>
</Form>
</> </>
); );
} }
@@ -1170,13 +1220,13 @@ export function PolicyOtpEmailSection({
emailEnabled emailEnabled
}: PolicyOtpEmailSectionProps) { }: PolicyOtpEmailSectionProps) {
const t = useTranslations(); const t = useTranslations();
const [isOpen, setIsOpen] = useState(false); const [isExpanded, setIsExpanded] = useState(false);
const [whitelistEnabled, setWhitelistEnabled] = useState(false); const [whitelistEnabled, setWhitelistEnabled] = useState(false);
const [activeEmailTagIndex, setActiveEmailTagIndex] = useState< const [activeEmailTagIndex, setActiveEmailTagIndex] = useState<
number | null number | null
>(null); >(null);
if (!isOpen) { if (!isExpanded) {
return ( return (
<SettingsSection> <SettingsSection>
<SettingsSectionHeader> <SettingsSectionHeader>
@@ -1191,7 +1241,7 @@ export function PolicyOtpEmailSection({
<Button <Button
type="button" type="button"
variant="outline" variant="outline"
onClick={() => setIsOpen(true)} onClick={() => setIsExpanded(true)}
> >
<Plus className="mr-2 h-4 w-4" /> <Plus className="mr-2 h-4 w-4" />
{t("resourcePolicyOtpEmailAdd")} {t("resourcePolicyOtpEmailAdd")}
@@ -1332,7 +1382,7 @@ export function PolicyRulesSection({
isMaxmindAsnAvailable isMaxmindAsnAvailable
}: PolicyRulesSectionProps) { }: PolicyRulesSectionProps) {
const t = useTranslations(); const t = useTranslations();
const [isOpen, setIsOpen] = useState(false); const [isExpanded, setIsExpanded] = useState(false);
const [rules, setRules] = useState<LocalRule[]>([]); const [rules, setRules] = useState<LocalRule[]>([]);
const [rulesEnabled, setRulesEnabled] = useState(false); const [rulesEnabled, setRulesEnabled] = useState(false);
const [openAddRuleCountrySelect, setOpenAddRuleCountrySelect] = const [openAddRuleCountrySelect, setOpenAddRuleCountrySelect] =
@@ -1829,7 +1879,7 @@ export function PolicyRulesSection({
state: { pagination: { pageIndex: 0, pageSize: 1000 } } state: { pagination: { pageIndex: 0, pageSize: 1000 } }
}); });
if (!isOpen) { if (!isExpanded) {
return ( return (
<SettingsSection> <SettingsSection>
<SettingsSectionHeader> <SettingsSectionHeader>
@@ -1844,7 +1894,7 @@ export function PolicyRulesSection({
<Button <Button
type="button" type="button"
variant="outline" variant="outline"
onClick={() => setIsOpen(true)} onClick={() => setIsExpanded(true)}
> >
<Plus className="mr-2 h-4 w-4" /> <Plus className="mr-2 h-4 w-4" />
{t("resourcePolicyRulesAdd")} {t("resourcePolicyRulesAdd")}