mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-04-13 13:08:41 +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>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<IdentityTraits schema={detailIdentitySchema} identity={detailIdentity}/>
|
||||
<IdentityTraits
|
||||
schema={detailIdentitySchema}
|
||||
identity={detailIdentity}
|
||||
disabled={!pmEditUserTraits}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
:
|
||||
|
|
|
@ -15,6 +15,7 @@ interface DynamicFormProps<T extends FieldValues> {
|
|||
onValid: SubmitHandler<T>,
|
||||
onInvalid: SubmitErrorHandler<T>,
|
||||
submitLabel?: string,
|
||||
disabled?: boolean,
|
||||
}
|
||||
|
||||
export function DynamicForm<T extends FieldValues>(
|
||||
|
@ -25,6 +26,7 @@ export function DynamicForm<T extends FieldValues>(
|
|||
onValid,
|
||||
onInvalid,
|
||||
submitLabel,
|
||||
disabled,
|
||||
}: DynamicFormProps<T>,
|
||||
) {
|
||||
|
||||
|
@ -48,7 +50,7 @@ export function DynamicForm<T extends FieldValues>(
|
|||
key={fullFieldName}
|
||||
render={({ field }) => (
|
||||
<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>
|
||||
</FormItem>
|
||||
)}
|
||||
|
@ -65,7 +67,7 @@ export function DynamicForm<T extends FieldValues>(
|
|||
<FormItem>
|
||||
<FormLabel>{value.title}</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder={value.title} {...field} />
|
||||
<Input placeholder={value.title} {...field} disabled={disabled}/>
|
||||
</FormControl>
|
||||
<FormDescription>{value.description}</FormDescription>
|
||||
</FormItem>
|
||||
|
@ -87,7 +89,7 @@ export function DynamicForm<T extends FieldValues>(
|
|||
<Button
|
||||
key="submit"
|
||||
type="submit"
|
||||
disabled={!form.formState.isDirty}
|
||||
disabled={!form.formState.isDirty || disabled}
|
||||
>
|
||||
{submitLabel ?? 'Submit'}
|
||||
</Button>
|
||||
|
|
|
@ -16,9 +16,10 @@ import { useState } from 'react';
|
|||
interface IdentityTraitFormProps {
|
||||
schema: KratosSchema;
|
||||
identity: Identity;
|
||||
disabled: boolean;
|
||||
}
|
||||
|
||||
export function IdentityTraits({ schema, identity }: IdentityTraitFormProps) {
|
||||
export function IdentityTraits({ schema, identity, disabled }: IdentityTraitFormProps) {
|
||||
|
||||
const [currentIdentity, setCurrentIdentity] = useState(identity);
|
||||
|
||||
|
@ -74,10 +75,11 @@ export function IdentityTraits({ schema, identity }: IdentityTraitFormProps) {
|
|||
return (
|
||||
<DynamicForm
|
||||
form={form}
|
||||
disabled={disabled}
|
||||
properties={schema.properties.traits.properties}
|
||||
onValid={onValid}
|
||||
onInvalid={onInvalid}
|
||||
submitLabel="Update Identity"
|
||||
submitLabel={disabled ? 'Insufficient permissions' : 'Update Identity'}
|
||||
>
|
||||
<FormField
|
||||
{...form.register('metadata_public')}
|
||||
|
@ -86,7 +88,7 @@ export function IdentityTraits({ schema, identity }: IdentityTraitFormProps) {
|
|||
<FormItem>
|
||||
<FormLabel>Public Metadata</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea placeholder="Public Metadata" {...field} />
|
||||
<Textarea placeholder="Public Metadata" {...field} disabled={disabled}/>
|
||||
</FormControl>
|
||||
<FormDescription>This has to be valid JSON</FormDescription>
|
||||
</FormItem>
|
||||
|
@ -99,7 +101,7 @@ export function IdentityTraits({ schema, identity }: IdentityTraitFormProps) {
|
|||
<FormItem>
|
||||
<FormLabel>Admin Metadata</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea placeholder="Admin Metadata" {...field} />
|
||||
<Textarea placeholder="Admin Metadata" {...field} disabled={disabled}/>
|
||||
</FormControl>
|
||||
<FormDescription>This has to be valid JSON</FormDescription>
|
||||
</FormItem>
|
||||
|
|
Loading…
Add table
Reference in a new issue