mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-04-16 13:49:28 +00:00
NORY-59: disable identity traits form if edit permission is missing
This commit is contained in:
parent
3151103195
commit
50bedbb976
3 changed files with 16 additions and 8 deletions
|
@ -143,7 +143,11 @@ export default async function UserDetailsPage({ params }: { params: Promise<{ id
|
||||||
schema</CardDescription>
|
schema</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<IdentityTraits schema={detailIdentitySchema} identity={detailIdentity}/>
|
<IdentityTraits
|
||||||
|
schema={detailIdentitySchema}
|
||||||
|
identity={detailIdentity}
|
||||||
|
disabled={!pmEditUserTraits}
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
:
|
:
|
||||||
|
|
|
@ -15,6 +15,7 @@ interface DynamicFormProps<T extends FieldValues> {
|
||||||
onValid: SubmitHandler<T>,
|
onValid: SubmitHandler<T>,
|
||||||
onInvalid: SubmitErrorHandler<T>,
|
onInvalid: SubmitErrorHandler<T>,
|
||||||
submitLabel?: string,
|
submitLabel?: string,
|
||||||
|
disabled?: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DynamicForm<T extends FieldValues>(
|
export function DynamicForm<T extends FieldValues>(
|
||||||
|
@ -25,6 +26,7 @@ export function DynamicForm<T extends FieldValues>(
|
||||||
onValid,
|
onValid,
|
||||||
onInvalid,
|
onInvalid,
|
||||||
submitLabel,
|
submitLabel,
|
||||||
|
disabled,
|
||||||
}: DynamicFormProps<T>,
|
}: DynamicFormProps<T>,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -48,7 +50,7 @@ export function DynamicForm<T extends FieldValues>(
|
||||||
key={fullFieldName}
|
key={fullFieldName}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="flex items-center space-x-2 space-y-0">
|
<FormItem className="flex items-center space-x-2 space-y-0">
|
||||||
<Checkbox {...field} checked={field.value}/>
|
<Checkbox {...field} disabled={disabled} checked={field.value}/>
|
||||||
<FormLabel>{key}</FormLabel>
|
<FormLabel>{key}</FormLabel>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
|
@ -65,7 +67,7 @@ export function DynamicForm<T extends FieldValues>(
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>{value.title}</FormLabel>
|
<FormLabel>{value.title}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder={value.title} {...field} />
|
<Input placeholder={value.title} {...field} disabled={disabled}/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>{value.description}</FormDescription>
|
<FormDescription>{value.description}</FormDescription>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
@ -87,7 +89,7 @@ export function DynamicForm<T extends FieldValues>(
|
||||||
<Button
|
<Button
|
||||||
key="submit"
|
key="submit"
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!form.formState.isDirty}
|
disabled={!form.formState.isDirty || disabled}
|
||||||
>
|
>
|
||||||
{submitLabel ?? 'Submit'}
|
{submitLabel ?? 'Submit'}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -16,9 +16,10 @@ import { useState } from 'react';
|
||||||
interface IdentityTraitFormProps {
|
interface IdentityTraitFormProps {
|
||||||
schema: KratosSchema;
|
schema: KratosSchema;
|
||||||
identity: Identity;
|
identity: Identity;
|
||||||
|
disabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function IdentityTraits({ schema, identity }: IdentityTraitFormProps) {
|
export function IdentityTraits({ schema, identity, disabled }: IdentityTraitFormProps) {
|
||||||
|
|
||||||
const [currentIdentity, setCurrentIdentity] = useState(identity);
|
const [currentIdentity, setCurrentIdentity] = useState(identity);
|
||||||
|
|
||||||
|
@ -74,10 +75,11 @@ export function IdentityTraits({ schema, identity }: IdentityTraitFormProps) {
|
||||||
return (
|
return (
|
||||||
<DynamicForm
|
<DynamicForm
|
||||||
form={form}
|
form={form}
|
||||||
|
disabled={disabled}
|
||||||
properties={schema.properties.traits.properties}
|
properties={schema.properties.traits.properties}
|
||||||
onValid={onValid}
|
onValid={onValid}
|
||||||
onInvalid={onInvalid}
|
onInvalid={onInvalid}
|
||||||
submitLabel="Update Identity"
|
submitLabel={disabled ? 'Insufficient permissions' : 'Update Identity'}
|
||||||
>
|
>
|
||||||
<FormField
|
<FormField
|
||||||
{...form.register('metadata_public')}
|
{...form.register('metadata_public')}
|
||||||
|
@ -86,7 +88,7 @@ export function IdentityTraits({ schema, identity }: IdentityTraitFormProps) {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Public Metadata</FormLabel>
|
<FormLabel>Public Metadata</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Textarea placeholder="Public Metadata" {...field} />
|
<Textarea placeholder="Public Metadata" {...field} disabled={disabled}/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>This has to be valid JSON</FormDescription>
|
<FormDescription>This has to be valid JSON</FormDescription>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
@ -99,7 +101,7 @@ export function IdentityTraits({ schema, identity }: IdentityTraitFormProps) {
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Admin Metadata</FormLabel>
|
<FormLabel>Admin Metadata</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Textarea placeholder="Admin Metadata" {...field} />
|
<Textarea placeholder="Admin Metadata" {...field} disabled={disabled}/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormDescription>This has to be valid JSON</FormDescription>
|
<FormDescription>This has to be valid JSON</FormDescription>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
Loading…
Add table
Reference in a new issue