NORY-22: add missing UI for boolean traits

This commit is contained in:
Markus Thielker 2024-12-13 20:20:11 +01:00
parent 4736148219
commit 206a40baed
No known key found for this signature in database
2 changed files with 20 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import { z } from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';
import { toast } from 'sonner';
import { Identity } from '@ory/client';
import { Checkbox } from '@/components/ui/checkbox';
interface IdentityTraitFormProps {
schema: KratosSchema;
@ -21,6 +22,21 @@ function renderUiNodes(form: UseFormReturn, properties: KratosSchemaProperties,
return Object.entries(properties).map(([key, value]) => {
if (value.type === 'object') {
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 {
return (
<FormField

View file

@ -51,6 +51,7 @@ export function generateZodSchema(properties: KratosSchemaProperties) {
zodType = zodType.max(value.maxLength);
}
break;
case 'integer':
case 'number':
zodType = z.number();
if (value.minimum) {
@ -60,6 +61,9 @@ export function generateZodSchema(properties: KratosSchemaProperties) {
zodType = zodType.max(value.maximum);
}
break;
case 'boolean':
zodType = z.boolean();
break;
case 'object':
const schemaCopy = structuredClone(schema);
schemaCopy.properties.traits.properties = value.properties!;