mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-04-19 00:51:18 +00:00
NORY-22: add missing UI for boolean traits
This commit is contained in:
parent
4736148219
commit
206a40baed
2 changed files with 20 additions and 0 deletions
|
@ -8,6 +8,7 @@ import { z } from 'zod';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { Identity } from '@ory/client';
|
import { Identity } from '@ory/client';
|
||||||
|
import { Checkbox } from '@/components/ui/checkbox';
|
||||||
|
|
||||||
interface IdentityTraitFormProps {
|
interface IdentityTraitFormProps {
|
||||||
schema: KratosSchema;
|
schema: KratosSchema;
|
||||||
|
@ -21,6 +22,21 @@ function renderUiNodes(form: UseFormReturn, properties: KratosSchemaProperties,
|
||||||
return Object.entries(properties).map(([key, value]) => {
|
return Object.entries(properties).map(([key, value]) => {
|
||||||
if (value.type === 'object') {
|
if (value.type === 'object') {
|
||||||
return renderUiNodes(form, value.properties!, key);
|
return renderUiNodes(form, value.properties!, key);
|
||||||
|
} else if (value.type === 'boolean') {
|
||||||
|
return (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={keyPrefix + key}
|
||||||
|
key={key}
|
||||||
|
className="space-y-0"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex items-center space-x-2 space-y-0">
|
||||||
|
<Checkbox {...field} checked={field.value}/>
|
||||||
|
<FormLabel>{value.title}</FormLabel>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<FormField
|
<FormField
|
||||||
|
|
|
@ -51,6 +51,7 @@ export function generateZodSchema(properties: KratosSchemaProperties) {
|
||||||
zodType = zodType.max(value.maxLength);
|
zodType = zodType.max(value.maxLength);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'integer':
|
||||||
case 'number':
|
case 'number':
|
||||||
zodType = z.number();
|
zodType = z.number();
|
||||||
if (value.minimum) {
|
if (value.minimum) {
|
||||||
|
@ -60,6 +61,9 @@ export function generateZodSchema(properties: KratosSchemaProperties) {
|
||||||
zodType = zodType.max(value.maximum);
|
zodType = zodType.max(value.maximum);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'boolean':
|
||||||
|
zodType = z.boolean();
|
||||||
|
break;
|
||||||
case 'object':
|
case 'object':
|
||||||
const schemaCopy = structuredClone(schema);
|
const schemaCopy = structuredClone(schema);
|
||||||
schemaCopy.properties.traits.properties = value.properties!;
|
schemaCopy.properties.traits.properties = value.properties!;
|
||||||
|
|
Loading…
Add table
Reference in a new issue