ui(admin): add "working" React admin ui
This commit is contained in:
parent
d1c7494933
commit
5402584508
199 changed files with 13387 additions and 151 deletions
56
resources/scripts/components/admin/users/RoleSelect.tsx
Normal file
56
resources/scripts/components/admin/users/RoleSelect.tsx
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { useFormikContext } from 'formik';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { searchRoles } from '@/api/admin/roles';
|
||||
import SearchableSelect, { Option } from '@/components/elements/SearchableSelect';
|
||||
import type { UserRole } from '@definitions/admin';
|
||||
|
||||
export default ({ selected }: { selected: UserRole | null }) => {
|
||||
const context = useFormikContext();
|
||||
|
||||
const [role, setRole] = useState<UserRole | null>(selected);
|
||||
const [roles, setRoles] = useState<UserRole[] | null>(null);
|
||||
|
||||
const onSearch = (query: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
searchRoles({ name: query })
|
||||
.then(roles => {
|
||||
setRoles(roles);
|
||||
return resolve();
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const onSelect = (role: UserRole | null) => {
|
||||
setRole(role);
|
||||
context.setFieldValue('adminRoleId', role?.id || null);
|
||||
};
|
||||
|
||||
const getSelectedText = (role: UserRole | null): string | undefined => {
|
||||
return role?.name;
|
||||
};
|
||||
|
||||
return (
|
||||
<SearchableSelect
|
||||
id={'adminRoleId'}
|
||||
name={'adminRoleId'}
|
||||
label={'Role'}
|
||||
placeholder={'Select a role...'}
|
||||
items={roles}
|
||||
selected={role}
|
||||
setSelected={setRole}
|
||||
setItems={setRoles}
|
||||
onSearch={onSearch}
|
||||
onSelect={onSelect}
|
||||
getSelectedText={getSelectedText}
|
||||
nullable
|
||||
>
|
||||
{roles?.map(d => (
|
||||
<Option key={d.id} selectId={'adminRoleId'} id={d.id} item={d} active={d.id === role?.id}>
|
||||
{d.name}
|
||||
</Option>
|
||||
))}
|
||||
</SearchableSelect>
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue