Skip to content

Commit 37a0370

Browse files
committed
Lint
1 parent b8a59da commit 37a0370

File tree

3 files changed

+63
-53
lines changed

3 files changed

+63
-53
lines changed

src/apps/admin/src/lib/components/DialogDeleteUser/DialogDeleteUser.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { FC, useCallback, useEffect, useState } from 'react'
2-
import { BaseModal, Button, InputText } from '~/libs/ui'
1+
import { ChangeEvent, FC, useCallback, useEffect, useState } from 'react'
32
import classNames from 'classnames'
43

4+
import { BaseModal, Button, InputText } from '~/libs/ui'
5+
56
import { UserInfo } from '../../models'
67

78
import styles from './DialogDeleteUser.module.scss'
@@ -37,11 +38,25 @@ export const DialogDeleteUser: FC<Props> = (props: Props) => {
3738
setError('Delete ticket URL is required')
3839
return
3940
}
41+
4042
setError('')
4143
props.onDelete(ticketUrl.trim())
4244
}, [props, ticketUrl])
4345

44-
const description = `Are you sure you want to DELETE user ${props.userInfo.handle} with email address ${props.userInfo.email}. If you are sure, please enter the associated delete request ticket URL below`
46+
const handleTicketUrlChange = useCallback(
47+
(event: ChangeEvent<HTMLInputElement>) => {
48+
if (error) {
49+
setError('')
50+
}
51+
52+
setTicketUrl(event.target.value)
53+
},
54+
[error],
55+
)
56+
57+
const description
58+
= `Are you sure you want to DELETE user ${props.userInfo.handle} with email address ${props.userInfo.email}. `
59+
+ 'If you are sure, please enter the associated delete request ticket URL below'
4560

4661
return (
4762
<BaseModal
@@ -60,12 +75,7 @@ export const DialogDeleteUser: FC<Props> = (props: Props) => {
6075
placeholder='https://'
6176
value={ticketUrl}
6277
error={error}
63-
onChange={event => {
64-
setTicketUrl(event.target.value)
65-
if (error) {
66-
setError('')
67-
}
68-
}}
78+
onChange={handleTicketUrlChange}
6979
disabled={props.isLoading}
7080
/>
7181

src/apps/admin/src/lib/components/UsersTable/UsersTable.tsx

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -341,21 +341,21 @@ export const UsersTable: FC<Props> = props => {
341341
return (
342342
<div className={styles.blockBtns}>
343343
{isTablet ? (
344-
<DropdownMenuButton
345-
options={[
346-
'Primary Email',
347-
'Roles',
348-
'Groups',
349-
'Terms',
350-
'SSO Logins',
351-
...(data.active
352-
? ['Deactivate', 'Delete']
353-
: ['Activate', 'Delete']),
354-
]}
355-
onSelectOption={onSelectOption}
356-
>
357-
<button type='button'>
358-
<IconOutline.DotsHorizontalIcon
344+
<DropdownMenuButton
345+
options={[
346+
'Primary Email',
347+
'Roles',
348+
'Groups',
349+
'Terms',
350+
'SSO Logins',
351+
...(data.active
352+
? ['Deactivate', 'Delete']
353+
: ['Activate', 'Delete']),
354+
]}
355+
onSelectOption={onSelectOption}
356+
>
357+
<button type='button'>
358+
<IconOutline.DotsHorizontalIcon
359359
width={15}
360360
/>
361361
</button>
@@ -381,20 +381,20 @@ export const UsersTable: FC<Props> = props => {
381381
</Button>
382382
</DropdownMenuButton>
383383
{data.active ? (
384-
<Button
385-
primary
386-
variant='danger'
387-
label='Deactivate'
388-
onClick={function onClick() {
389-
onSelectOption('Deactivate')
390-
}}
391-
disabled={isDeleting}
392-
/>
393-
) : (
394-
<Button
395-
primary
396-
variant='linkblue'
397-
label='Activate'
384+
<Button
385+
primary
386+
variant='danger'
387+
label='Deactivate'
388+
onClick={function onClick() {
389+
onSelectOption('Deactivate')
390+
}}
391+
disabled={isDeleting}
392+
/>
393+
) : (
394+
<Button
395+
primary
396+
variant='linkblue'
397+
label='Activate'
398398
onClick={function onClick() {
399399
onSelectOption('Activate')
400400
}}

src/apps/admin/src/lib/hooks/useManageUsers.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ import { handleError } from '../utils'
1515
/// ////////////////
1616

1717
type UsersState = {
18+
deletingUsers: { [key: string]: boolean }
1819
isLoading: boolean
19-
users: UserInfo[]
2020
page: number
21-
totalPages: number
2221
total: number
22+
totalPages: number
2323
updatingStatus: { [key: string]: boolean }
24-
deletingUsers: { [key: string]: boolean }
24+
users: UserInfo[]
2525
}
2626

2727
const UsersActionType = {
28+
DELETE_USER_DONE: 'DELETE_USER_DONE' as const,
29+
DELETE_USER_FAILED: 'DELETE_USER_FAILED' as const,
30+
DELETE_USER_INIT: 'DELETE_USER_INIT' as const,
2831
FETCH_USERS_DONE: 'FETCH_USERS_DONE' as const,
2932
FETCH_USERS_FAILED: 'FETCH_USERS_FAILED' as const,
3033
FETCH_USERS_INIT: 'FETCH_USERS_INIT' as const,
3134
SET_PAGE: 'SET_PAGE' as const,
3235
UPDATE_USER_STATUS_DONE: 'UPDATE_USER_STATUS_DONE' as const,
3336
UPDATE_USER_STATUS_FAILED: 'UPDATE_USER_STATUS_FAILED' as const,
3437
UPDATE_USER_STATUS_INIT: 'UPDATE_USER_STATUS_INIT' as const,
35-
DELETE_USER_INIT: 'DELETE_USER_INIT' as const,
36-
DELETE_USER_DONE: 'DELETE_USER_DONE' as const,
37-
DELETE_USER_FAILED: 'DELETE_USER_FAILED' as const,
3838
}
3939

4040
type UsersReducerAction =
@@ -45,7 +45,7 @@ type UsersReducerAction =
4545
}
4646
| {
4747
type: typeof UsersActionType.FETCH_USERS_DONE
48-
payload: { users: UserInfo[]; page: number; totalPages: number; total: number }
48+
payload: { page: number; total: number; totalPages: number; users: UserInfo[] }
4949
}
5050
| { type: typeof UsersActionType.SET_PAGE; payload: number }
5151
| {
@@ -110,14 +110,14 @@ const reducer = (
110110
const userInfo = action.payload
111111
return {
112112
...previousState,
113-
updatingStatus: {
114-
...previousState.updatingStatus,
115-
[userInfo.id]: false,
116-
},
117113
deletingUsers: {
118114
...previousState.deletingUsers,
119115
[userInfo.id]: false,
120116
},
117+
updatingStatus: {
118+
...previousState.updatingStatus,
119+
[userInfo.id]: false,
120+
},
121121
users: _.map(previousState.users, item => (userInfo.id !== item.id ? item : userInfo)),
122122
}
123123
}
@@ -150,8 +150,8 @@ const reducer = (
150150
...previousState.deletingUsers,
151151
[userId]: false,
152152
},
153-
users: previousState.users.filter(user => user.id !== userId),
154153
total: Math.max(previousState.total - 1, 0),
154+
users: previousState.users.filter(user => user.id !== userId),
155155
}
156156
}
157157

@@ -199,12 +199,12 @@ export interface useManageUsersProps {
199199
*/
200200
export function useManageUsers(): useManageUsersProps {
201201
const [state, dispatch] = useReducer(reducer, {
202+
deletingUsers: {},
202203
isLoading: false,
203204
page: 1,
204205
total: 0,
205206
totalPages: 0,
206207
updatingStatus: {},
207-
deletingUsers: {},
208208
users: [],
209209
})
210210
const filterRef = useRef('')
@@ -351,14 +351,14 @@ export function useManageUsers(): useManageUsersProps {
351351
)
352352

353353
return {
354-
doSearchUsers,
354+
deletingUsers: state.deletingUsers,
355355
doDeleteUser,
356+
doSearchUsers,
356357
doUpdateStatus,
357358
isLoading: state.isLoading,
358359
onPageChange,
359360
page: state.page,
360361
totalPages: state.totalPages,
361-
deletingUsers: state.deletingUsers,
362362
updatingStatus: state.updatingStatus,
363363
users: state.users,
364364
}

0 commit comments

Comments
 (0)