Files
ItzLinaton c900fc0ccc Feat: Random password generator (V2) (#7272)
Added a secure password generator to admin customer user manager and
user account manager as shown below:

## Extra Details:
- Added a reusable password field component with:
  - 17-character random password generation
  - Uppercase and lowercase letters
  - Numbers
  - Symbols
  - Password visibility toggle button
  - Clipboard copy button after the new password is generated
- Integrated the feature into:
  - Admin customer user creation area
  - Admin customer user editing area
  - Customer User account settings

<img width="430" height="466"
alt="{2DD29137-22E3-4446-8DB5-4F37AD322DF2}"
src="https://github.com/user-attachments/assets/03ef614a-3f4e-4ba6-bdbc-1a99e07959c6"
/>

<img width="427" height="120"
alt="{A3073146-78CD-459C-A837-EBAB72E8ABA4}"
src="https://github.com/user-attachments/assets/5c9cf583-4941-4c0d-893a-fe85c4e46f3c"
/>

<img width="413" height="142"
alt="{2DB05B11-7781-403D-ABC1-CEF11D31E1E8}"
src="https://github.com/user-attachments/assets/0131b770-9120-4f14-8bbd-8dfc374e6263"
/>

<img width="457" height="249"
alt="{8AA4DACE-CBA4-41F1-A5FA-F1EEB3B72632}"
src="https://github.com/user-attachments/assets/2f3004fe-74b2-4060-82eb-ac3f12d5f00f"
/>
2026-11-01 19:50:22 -05:00

114 lines
4.0 KiB
TypeScript

import type { UserValues } from '@/api/admin/users/queries';
import type { AppForm } from '@/components/form';
import type { SelectOption } from '@/components/ui/Select';
import TitledGreyBox from '@/components/elements/TitledGreyBox';
import {
validateFirstName,
validateLastName,
validateUserEmail,
validateUsername,
validateUserPassword,
} from '@/components/admin/users/userForm';
interface Props {
form: AppForm<UserValues>;
languageOptions: SelectOption[];
languagesLoading: boolean;
}
const AccountFields = ({ form }: Pick<Props, 'form'>) => (
<div className='space-y-6'>
<form.AppField name='email' validators={{ onChange: validateUserEmail }}>
{(field) => (
<field.TextField
type='email'
id='email'
label='Email Address'
description='The email address this user will sign in and receive notifications with.'
/>
)}
</form.AppField>
<form.AppField name='username' validators={{ onChange: validateUsername }}>
{(field) => (
<field.TextField
type='text'
id='username'
label='Username'
description='A unique username used to identify this account.'
/>
)}
</form.AppField>
<div className='grid grid-cols-1 sm:grid-cols-2 gap-6'>
<form.AppField name='nameFirst' validators={{ onChange: validateFirstName }}>
{(field) => <field.TextField type='text' id='name_first' label='First Name' />}
</form.AppField>
<form.AppField name='nameLast' validators={{ onChange: validateLastName }}>
{(field) => <field.TextField type='text' id='name_last' label='Last Name' />}
</form.AppField>
</div>
</div>
);
const AuthenticationFields = ({ form, languageOptions, languagesLoading }: Props) => (
<div className='space-y-6'>
<form.AppField name='password' validators={{ onChange: validateUserPassword }}>
{(field) => (
<field.PasswordField
id='password'
label='Password'
description='Leave blank to email this user a setup link to choose their own.'
autoComplete='new-password'
/>
)}
</form.AppField>
<form.AppField
name='language'
validators={{
onChange: ({ value }) => (value.length >= 1 ? undefined : 'A language must be provided.'),
}}
>
{(field) => (
<field.SelectField
id='language'
label='Language'
options={languageOptions}
disabled={languagesLoading}
placeholder='Select a language'
description='The default language for this account.'
/>
)}
</form.AppField>
</div>
);
const AccessFields = ({ form }: Pick<Props, 'form'>) => (
<form.AppField name='rootAdmin'>
{(field) => (
<field.SwitchField
label='Administrator'
description='Grant this account full administrative access to the Panel.'
/>
)}
</form.AppField>
);
export default function UserFormFields({ form, languageOptions, languagesLoading }: Props) {
return (
<div className='space-y-6'>
<TitledGreyBox title='Account Details'>
<AccountFields form={form} />
</TitledGreyBox>
<TitledGreyBox title='Authentication'>
<AuthenticationFields
form={form}
languageOptions={languageOptions}
languagesLoading={languagesLoading}
/>
</TitledGreyBox>
<TitledGreyBox title='Access'>
<AccessFields form={form} />
</TitledGreyBox>
</div>
);
}