Skip to content

Commit 9ba84fe

Browse files
authored
[Feature]: Support activating/deactivating users via the UI #2427 (#2440)
1 parent 2463943 commit 9ba84fe

File tree

5 files changed

+55
-25
lines changed

5 files changed

+55
-25
lines changed

frontend/src/locale/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@
512512
"token": "Token",
513513
"token_description": "Specify use your personal access token",
514514
"global_role": "Global role",
515+
"active": "Active",
516+
"active_description": "Specify user activation",
517+
"activated": "Activated",
518+
"deactivated": "Deactivated",
515519
"email": "Email",
516520
"created_at": "Created at",
517521
"account": "User",

frontend/src/pages/User/Edit/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const UserEdit: React.FC = () => {
8484
const onSubmitHandler = async (userData: Partial<IUser>) => {
8585
try {
8686
const data = await updateUser({
87-
...pick(userData, ['global_role', 'email']),
87+
...pick(userData, ['global_role', 'email', 'active']),
8888
username: paramUserName,
8989
}).unwrap();
9090

frontend/src/pages/User/Form/index.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919

2020
import { copyToClipboard } from 'libs';
2121

22-
import { TRoleSelectOption } from './types';
22+
import { TActiveSelectOption, TRoleSelectOption } from './types';
2323

2424
export interface Props {
2525
initialValues?: IUserWithCreds;
@@ -44,22 +44,37 @@ export const UserForm: React.FC<Props> = ({
4444
const isEditing = !!initialValues;
4545

4646
const { handleSubmit, control } = useForm<IUser>({
47-
defaultValues: initialValues ?? {
48-
global_role: 'user',
49-
},
47+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
48+
// @ts-ignore
49+
defaultValues: initialValues
50+
? { ...initialValues, active: initialValues.active ? 'active' : 'inactive' }
51+
: {
52+
global_role: 'user',
53+
active: 'active',
54+
},
5055
});
5156

5257
const roleSelectOptions: TRoleSelectOption[] = [
5358
{ label: t('roles.admin'), value: 'admin' },
5459
{ label: t('roles.user'), value: 'user' },
5560
];
5661

62+
const activeSelectOptions: TActiveSelectOption[] = [
63+
{ label: t('users.activated'), value: 'active' },
64+
{ label: t('users.deactivated'), value: 'inactive' },
65+
];
66+
5767
const onCopyToken = () => {
5868
copyToClipboard(initialValues?.creds.token ?? '');
5969
};
6070

6171
const onSubmit = (data: IUser) => {
62-
onSubmitProp(data);
72+
onSubmitProp({
73+
...data,
74+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
75+
// @ts-ignore
76+
active: data.active === 'active',
77+
});
6378
};
6479

6580
const isDisabledEmailAndRoleField = () => {
@@ -124,6 +139,15 @@ export const UserForm: React.FC<Props> = ({
124139
options={roleSelectOptions}
125140
disabled={isDisabledEmailAndRoleField()}
126141
/>
142+
143+
<FormSelect
144+
label={t('users.active')}
145+
description={t('users.active_description')}
146+
control={control}
147+
name="active"
148+
options={activeSelectOptions}
149+
disabled={isDisabledEmailAndRoleField()}
150+
/>
127151
</ColumnLayout>
128152

129153
{initialValues && (
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export type TRoleSelectOption = { label: string; value: TProjectRole; disabled?: boolean };
2+
export type TActiveSelectOption = { label: string; value: 'active' | 'inactive'; disabled?: boolean };

frontend/src/types/user.d.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
declare type TUserRole = 'user' | 'admin';
2-
declare type TUserPermission = 'CAN_CREATE_PROJECTS'
3-
declare type TUserPermissionKeys = 'can_create_projects'
2+
declare type TUserPermission = 'CAN_CREATE_PROJECTS';
3+
declare type TUserPermissionKeys = 'can_create_projects';
44

55
declare interface IUserResponseData {
6-
id: string,
6+
id: string;
77
username: string;
8-
global_role: TUserRole
9-
email: string | null,
10-
permissions: Record<TUserPermissionKeys, boolean>
8+
global_role: TUserRole;
9+
email: string | null;
10+
permissions: Record<TUserPermissionKeys, boolean>;
1111
}
1212

1313
declare interface IUser {
14-
id: string,
14+
id: string;
1515
username: string;
16-
global_role: TUserRole
17-
email: string | null,
18-
permissions: TUserPermission[],
19-
created_at: string
16+
global_role: TUserRole;
17+
email: string | null;
18+
permissions: TUserPermission[];
19+
created_at: string;
20+
active: boolean;
2021
}
2122

2223
declare interface IUserWithCreds extends IUser {
23-
"creds": {
24-
"token": string
25-
}
24+
creds: {
25+
token: string;
26+
};
2627
}
2728

28-
declare interface IUserAuthData extends Pick<IUserWithCreds['creds'], 'token'>{}
29+
declare interface IUserAuthData extends Pick<IUserWithCreds['creds'], 'token'> {}
2930

3031
declare interface IUserBillingInfo {
31-
balance: number
32-
is_payment_method_attached: boolean,
33-
default_payment_amount: number,
34-
billing_history: IPayment[]
32+
balance: number;
33+
is_payment_method_attached: boolean;
34+
default_payment_amount: number;
35+
billing_history: IPayment[];
3536
}

0 commit comments

Comments
 (0)