Skip to content

Commit 2be1b57

Browse files
authored
Merge pull request #1070 from topcoder-platform/diazz-admin-f2f-30376773
Topcoder Admin App - Misc Update 0505
2 parents af68445 + 88fe2bf commit 2be1b57

File tree

16 files changed

+147
-83
lines changed

16 files changed

+147
-83
lines changed

src/apps/admin/src/challenge-management/ChallengeManagementPage/ChallengeManagementPage.tsx

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
useState,
1111
} from 'react'
1212
import { useSearchParams } from 'react-router-dom'
13+
import _ from 'lodash'
1314

1415
import { LoadingSpinner, PageDivider, PageTitle } from '~/libs/ui'
1516
import { PaginatedResponse } from '~/libs/core'
@@ -36,6 +37,17 @@ import { useEventCallback } from '../../lib/hooks'
3637

3738
import styles from './ChallengeManagementPage.module.scss'
3839

40+
const defaultFilter: ChallengeFilterCriteria = {
41+
challengeId: '',
42+
legacyId: 0,
43+
name: '',
44+
page: 1,
45+
perPage: 25,
46+
status: ChallengeStatus.Active,
47+
track: null!, // eslint-disable-line @typescript-eslint/no-non-null-assertion, unicorn/no-null
48+
type: null!, // eslint-disable-line @typescript-eslint/no-non-null-assertion, unicorn/no-null
49+
}
50+
3951
/**
4052
* Challenge Management page.
4153
*/
@@ -45,15 +57,9 @@ export const ChallengeManagementPage: FC = () => {
4557
ChallengeFilterCriteria,
4658
Dispatch<SetStateAction<ChallengeFilterCriteria>>,
4759
] = useState<ChallengeFilterCriteria>({
48-
challengeId: '',
49-
legacyId: 0,
50-
name: '',
51-
page: 1,
52-
perPage: 25,
53-
status: ChallengeStatus.Active,
54-
track: null!, // eslint-disable-line @typescript-eslint/no-non-null-assertion, unicorn/no-null
55-
type: null!, // eslint-disable-line @typescript-eslint/no-non-null-assertion, unicorn/no-null
60+
...defaultFilter,
5661
})
62+
const disableReset = useMemo(() => _.isEqual(filterCriteria, defaultFilter), [filterCriteria])
5763
const [challenges, setChallenges]: [
5864
Array<Challenge>,
5965
Dispatch<SetStateAction<Array<Challenge>>>,
@@ -119,19 +125,6 @@ export const ChallengeManagementPage: FC = () => {
119125
}
120126
}, [pageChangeEvent]) // eslint-disable-line react-hooks/exhaustive-deps -- missing dependency: search
121127

122-
// Reset
123-
const [resetEvent, setResetEvent] = useState(false)
124-
useEffect(() => {
125-
if (resetEvent) {
126-
search()
127-
setResetEvent(false)
128-
}
129-
}, [resetEvent]) // eslint-disable-line react-hooks/exhaustive-deps -- missing dependency: search
130-
131-
const handleReset = useEventCallback(() => {
132-
previousPageChangeEvent.current = false
133-
setResetEvent(true)
134-
})
135128
const handlePageChange = useEventCallback((page: number) => {
136129
setFilterCriteria({ ...filterCriteria, page })
137130
setPageChangeEvent(true)
@@ -149,12 +142,15 @@ export const ChallengeManagementPage: FC = () => {
149142
onFilterCriteriaChange={setFilterCriteria}
150143
onSearch={search}
151144
disabled={searching || !filtersInited}
152-
showResetButton={
153-
previousPageChangeEvent.current
154-
&& searched
155-
&& challenges.length === 0
156-
}
157-
onReset={handleReset}
145+
onReset={function onReset() {
146+
setFilterCriteria({
147+
...defaultFilter,
148+
})
149+
setTimeout(() => {
150+
search()
151+
})
152+
}}
153+
disableReset={disableReset}
158154
/>
159155
<PageDivider />
160156
{searching && (

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ export const BillingAccountResourcesTable: FC<Props> = (props: Props) => {
4444
propertyName: 'name',
4545
type: 'text',
4646
},
47-
{
48-
label: 'Status',
49-
propertyName: 'status',
50-
type: 'text',
51-
},
5247
{
5348
className: styles.blockColumnAction,
5449
label: '',
@@ -81,21 +76,8 @@ export const BillingAccountResourcesTable: FC<Props> = (props: Props) => {
8176
},
8277
],
8378
[
84-
{
85-
label: 'Status label',
86-
mobileType: 'label',
87-
propertyName: 'status',
88-
renderer: () => <div>Status:</div>,
89-
type: 'element',
90-
},
9179
{
9280
...columns[1],
93-
mobileType: 'last-value',
94-
},
95-
],
96-
[
97-
{
98-
...columns[2],
9981
colSpan: 2,
10082
mobileType: 'last-value',
10183
},

src/apps/admin/src/lib/components/BillingAccountsFilter/BillingAccountsFilter.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
display: flex;
4545
justify-content: flex-end;
4646
align-items: flex-start;
47-
gap: 30px;
47+
gap: 15px;
4848
flex-wrap: wrap;
4949

5050
@include ltemd {

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,30 @@ interface Props {
2727
onSubmitForm?: (data: FormBillingAccountsFilter) => void
2828
}
2929

30+
const defaultValues: FormBillingAccountsFilter = {
31+
endDate: undefined,
32+
name: '',
33+
startDate: undefined,
34+
status: '1',
35+
user: '',
36+
}
37+
3038
export const BillingAccountsFilter: FC<Props> = (props: Props) => {
3139
const maxDate = useMemo(() => moment()
3240
.add(20, 'y')
3341
.toDate(), [])
3442
const {
3543
register,
44+
reset,
3645
handleSubmit,
3746
control,
38-
formState: { isValid },
47+
formState: { isValid, isDirty },
3948
}: UseFormReturn<FormBillingAccountsFilter> = useForm({
40-
defaultValues: {
41-
status: '1',
42-
},
49+
defaultValues,
4350
mode: 'all',
4451
resolver: yupResolver(formBillingAccountsFilterSchema),
4552
})
53+
4654
const onSubmit = useCallback(
4755
(data: FormBillingAccountsFilter) => {
4856
props.onSubmitForm?.(data)
@@ -162,6 +170,19 @@ export const BillingAccountsFilter: FC<Props> = (props: Props) => {
162170
>
163171
Filter
164172
</Button>
173+
<Button
174+
secondary
175+
onClick={function onClick() {
176+
reset(defaultValues)
177+
setTimeout(() => {
178+
onSubmit(defaultValues)
179+
})
180+
}}
181+
size='lg'
182+
disabled={!isDirty}
183+
>
184+
Reset
185+
</Button>
165186
</div>
166187
</form>
167188
)

src/apps/admin/src/lib/components/ChallengeFilters/ChallengeFilters.module.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
gap: 15px 30px;
1717
}
1818

19-
.searchButton {
20-
margin-left: auto;
21-
}
22-
2319
@media (max-width: #{$lg-max}) {
2420
.filters {
2521
grid-template-columns: 1fr 1fr;
@@ -32,3 +28,10 @@
3228
}
3329
}
3430
}
31+
32+
.blockBtns {
33+
margin-left: auto;
34+
display: flex;
35+
gap: 15px;
36+
justify-content: flex-end;
37+
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import styles from './ChallengeFilters.module.scss'
1919
interface ChallengeFiltersProps {
2020
filterCriteria: ChallengeFilterCriteria
2121
disabled: boolean
22-
showResetButton: boolean
2322
onFilterCriteriaChange: (newFilterCriteria: ChallengeFilterCriteria) => void
2423
onSearch: () => void
2524
onReset: () => void
25+
disableReset: boolean
2626
}
2727

2828
const ChallengeFilters: FC<ChallengeFiltersProps> = props => {
@@ -188,28 +188,24 @@ const ChallengeFilters: FC<ChallengeFiltersProps> = props => {
188188
disabled={props.disabled}
189189
/>
190190
</div>
191-
{!props.showResetButton && (
191+
<div className={styles.blockBtns}>
192192
<Button
193193
primary
194-
className={styles.searchButton}
195194
onClick={props.onSearch}
196195
disabled={props.disabled}
197196
size='lg'
198197
>
199198
Search
200199
</Button>
201-
)}
202-
{props.showResetButton && (
203200
<Button
204201
secondary
205-
className={styles.searchButton}
206202
onClick={handleReset}
207-
disabled={props.disabled}
203+
disabled={props.disabled || props.disableReset}
208204
size='lg'
209205
>
210206
Reset
211207
</Button>
212-
)}
208+
</div>
213209
</div>
214210
)
215211
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,13 @@ const ChallengeList: FC<ChallengeListProps> = props => {
267267
propertyName: 'name',
268268
renderer: (challenge: Challenge) => (
269269
// eslint-disable-next-line jsx-a11y/anchor-is-valid
270-
<a href='#' className={styles.challengeTitle}>
270+
<a
271+
href={`${EnvironmentConfig.ADMIN.CHALLENGE_URL}/${challenge.id}`}
272+
className={styles.challengeTitle}
273+
onClick={function onClick() {
274+
window.location.href = `${EnvironmentConfig.ADMIN.CHALLENGE_URL}/${challenge.id}`
275+
}}
276+
>
271277
{challenge.name}
272278
</a>
273279
),

src/apps/admin/src/lib/components/ClientsFilter/ClientsFilter.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
display: flex;
2525
justify-content: flex-end;
2626
align-items: flex-start;
27-
gap: 30px;
27+
gap: 15px;
2828
flex-wrap: wrap;
2929

3030
@include ltemd {

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,25 @@ interface Props {
2727
onSubmitForm?: (data: FormClientsFilter) => void
2828
}
2929

30+
const defaultValues: FormClientsFilter = {
31+
endDate: undefined,
32+
name: '',
33+
startDate: undefined,
34+
status: '1',
35+
}
36+
3037
export const ClientsFilter: FC<Props> = (props: Props) => {
3138
const maxDate = useMemo(() => moment()
3239
.add(20, 'y')
3340
.toDate(), [])
3441
const {
3542
register,
43+
reset,
3644
handleSubmit,
3745
control,
38-
formState: { isValid },
46+
formState: { isValid, isDirty },
3947
}: UseFormReturn<FormClientsFilter> = useForm({
40-
defaultValues: {
41-
status: '1',
42-
},
48+
defaultValues,
4349
mode: 'all',
4450
resolver: yupResolver(formClientsFilterSchema),
4551
})
@@ -149,6 +155,19 @@ export const ClientsFilter: FC<Props> = (props: Props) => {
149155
>
150156
Filter
151157
</Button>
158+
<Button
159+
secondary
160+
onClick={function onClick() {
161+
reset(defaultValues)
162+
setTimeout(() => {
163+
onSubmit(defaultValues)
164+
})
165+
}}
166+
size='lg'
167+
disabled={!isDirty}
168+
>
169+
Reset
170+
</Button>
152171
</div>
153172
</form>
154173
)

src/apps/admin/src/lib/components/ReviewSummaryList/ReviewSummaryList.module.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
}
1010
}
1111

12-
.challengeTitle {
12+
.challengeTitleText,
13+
.challengeTitleLink {
1314
min-width: 200px;
1415
padding: 0;
1516
justify-content: flex-start;
1617
border-radius: 0;
1718
color: $body-color;
1819
line-height: 16px;
1920
white-space: break-spaces;
21+
}
2022

23+
.challengeTitleLink {
2124
&:hover {
2225
color: $blue-110;
2326
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC, useMemo } from 'react'
22
import { useNavigate } from 'react-router-dom'
33

4+
import { EnvironmentConfig } from '~/config'
45
import { useWindowSize, WindowSize } from '~/libs/shared'
56
import { Button, LinkButton, Table, type TableColumn } from '~/libs/ui'
67
import { Sort } from '~/apps/gamification-admin/src/game-lib/pagination'
@@ -45,13 +46,17 @@ const ChallengeTitle: FC<{
4546
review: ReviewSummary
4647
}> = props => {
4748
const goToChallenge = useEventCallback(() => {
48-
window.location.href = `https://www.topcoder.com/challenges/${props.review.legacyChallengeId}`
49+
window.location.href = `${EnvironmentConfig.ADMIN.CHALLENGE_URL}/${props.review.legacyChallengeId}`
4950
})
5051

51-
return (
52-
<LinkButton onClick={goToChallenge} className={styles.challengeTitle}>
52+
return props.review.legacyChallengeId ? (
53+
<LinkButton onClick={goToChallenge} className={styles.challengeTitleLink}>
5354
{props.review.challengeName}
5455
</LinkButton>
56+
) : (
57+
<span className={styles.challengeTitleText}>
58+
{props.review.challengeName}
59+
</span>
5560
)
5661
}
5762

src/apps/admin/src/lib/components/UsersFilters/UsersFilters.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@
4444
font-size: 14px;
4545
color: $black-60;
4646
}
47+
48+
.blockBtns {
49+
display: flex;
50+
gap: 15px;
51+
justify-content: flex-end;
52+
}

0 commit comments

Comments
 (0)