-
Notifications
You must be signed in to change notification settings - Fork 10
Topcoder Admin App - Misc Update 0505 #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
useState, | ||
} from 'react' | ||
import { useSearchParams } from 'react-router-dom' | ||
import _ from 'lodash' | ||
|
||
import { LoadingSpinner, PageDivider, PageTitle } from '~/libs/ui' | ||
import { PaginatedResponse } from '~/libs/core' | ||
|
@@ -36,6 +37,17 @@ import { useEventCallback } from '../../lib/hooks' | |
|
||
import styles from './ChallengeManagementPage.module.scss' | ||
|
||
const defaultFilter: ChallengeFilterCriteria = { | ||
challengeId: '', | ||
legacyId: 0, | ||
name: '', | ||
page: 1, | ||
perPage: 25, | ||
status: ChallengeStatus.Active, | ||
track: null!, // eslint-disable-line @typescript-eslint/no-non-null-assertion, unicorn/no-null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
type: null!, // eslint-disable-line @typescript-eslint/no-non-null-assertion, unicorn/no-null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
} | ||
|
||
/** | ||
* Challenge Management page. | ||
*/ | ||
|
@@ -45,15 +57,9 @@ export const ChallengeManagementPage: FC = () => { | |
ChallengeFilterCriteria, | ||
Dispatch<SetStateAction<ChallengeFilterCriteria>>, | ||
] = useState<ChallengeFilterCriteria>({ | ||
challengeId: '', | ||
legacyId: 0, | ||
name: '', | ||
page: 1, | ||
perPage: 25, | ||
status: ChallengeStatus.Active, | ||
track: null!, // eslint-disable-line @typescript-eslint/no-non-null-assertion, unicorn/no-null | ||
type: null!, // eslint-disable-line @typescript-eslint/no-non-null-assertion, unicorn/no-null | ||
...defaultFilter, | ||
}) | ||
const disableReset = useMemo(() => _.isEqual(filterCriteria, defaultFilter), [filterCriteria]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider importing only the |
||
const [challenges, setChallenges]: [ | ||
Array<Challenge>, | ||
Dispatch<SetStateAction<Array<Challenge>>>, | ||
|
@@ -119,19 +125,6 @@ export const ChallengeManagementPage: FC = () => { | |
} | ||
}, [pageChangeEvent]) // eslint-disable-line react-hooks/exhaustive-deps -- missing dependency: search | ||
|
||
// Reset | ||
const [resetEvent, setResetEvent] = useState(false) | ||
useEffect(() => { | ||
if (resetEvent) { | ||
search() | ||
setResetEvent(false) | ||
} | ||
}, [resetEvent]) // eslint-disable-line react-hooks/exhaustive-deps -- missing dependency: search | ||
|
||
const handleReset = useEventCallback(() => { | ||
previousPageChangeEvent.current = false | ||
setResetEvent(true) | ||
}) | ||
const handlePageChange = useEventCallback((page: number) => { | ||
setFilterCriteria({ ...filterCriteria, page }) | ||
setPageChangeEvent(true) | ||
|
@@ -149,12 +142,15 @@ export const ChallengeManagementPage: FC = () => { | |
onFilterCriteriaChange={setFilterCriteria} | ||
onSearch={search} | ||
disabled={searching || !filtersInited} | ||
showResetButton={ | ||
previousPageChangeEvent.current | ||
&& searched | ||
&& challenges.length === 0 | ||
} | ||
onReset={handleReset} | ||
onReset={function onReset() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using an arrow function for |
||
setFilterCriteria({ | ||
...defaultFilter, | ||
}) | ||
setTimeout(() => { | ||
search() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
}) | ||
}} | ||
disableReset={disableReset} | ||
/> | ||
<PageDivider /> | ||
{searching && ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,22 +27,30 @@ interface Props { | |
onSubmitForm?: (data: FormBillingAccountsFilter) => void | ||
} | ||
|
||
const defaultValues: FormBillingAccountsFilter = { | ||
endDate: undefined, | ||
name: '', | ||
startDate: undefined, | ||
status: '1', | ||
user: '', | ||
} | ||
|
||
export const BillingAccountsFilter: FC<Props> = (props: Props) => { | ||
const maxDate = useMemo(() => moment() | ||
.add(20, 'y') | ||
.toDate(), []) | ||
const { | ||
register, | ||
reset, | ||
handleSubmit, | ||
control, | ||
formState: { isValid }, | ||
formState: { isValid, isDirty }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
}: UseFormReturn<FormBillingAccountsFilter> = useForm({ | ||
defaultValues: { | ||
status: '1', | ||
}, | ||
defaultValues, | ||
mode: 'all', | ||
resolver: yupResolver(formBillingAccountsFilterSchema), | ||
}) | ||
|
||
const onSubmit = useCallback( | ||
(data: FormBillingAccountsFilter) => { | ||
props.onSubmitForm?.(data) | ||
|
@@ -162,6 +170,19 @@ export const BillingAccountsFilter: FC<Props> = (props: Props) => { | |
> | ||
Filter | ||
</Button> | ||
<Button | ||
secondary | ||
onClick={function onClick() { | ||
reset(defaultValues) | ||
setTimeout(() => { | ||
onSubmit(defaultValues) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider providing a delay duration for |
||
}) | ||
}} | ||
size='lg' | ||
disabled={!isDirty} | ||
> | ||
Reset | ||
</Button> | ||
</div> | ||
</form> | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,10 @@ import styles from './ChallengeFilters.module.scss' | |
interface ChallengeFiltersProps { | ||
filterCriteria: ChallengeFilterCriteria | ||
disabled: boolean | ||
showResetButton: boolean | ||
onFilterCriteriaChange: (newFilterCriteria: ChallengeFilterCriteria) => void | ||
onSearch: () => void | ||
onReset: () => void | ||
disableReset: boolean | ||
} | ||
|
||
const ChallengeFilters: FC<ChallengeFiltersProps> = props => { | ||
|
@@ -188,28 +188,24 @@ const ChallengeFilters: FC<ChallengeFiltersProps> = props => { | |
disabled={props.disabled} | ||
/> | ||
</div> | ||
{!props.showResetButton && ( | ||
<div className={styles.blockBtns}> | ||
<Button | ||
primary | ||
className={styles.searchButton} | ||
onClick={props.onSearch} | ||
disabled={props.disabled} | ||
size='lg' | ||
> | ||
Search | ||
</Button> | ||
)} | ||
{props.showResetButton && ( | ||
<Button | ||
secondary | ||
className={styles.searchButton} | ||
onClick={handleReset} | ||
disabled={props.disabled} | ||
disabled={props.disabled || props.disableReset} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming |
||
size='lg' | ||
> | ||
Reset | ||
</Button> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,7 +267,13 @@ const ChallengeList: FC<ChallengeListProps> = props => { | |
propertyName: 'name', | ||
renderer: (challenge: Challenge) => ( | ||
// eslint-disable-next-line jsx-a11y/anchor-is-valid | ||
<a href='#' className={styles.challengeTitle}> | ||
<a | ||
href={`${EnvironmentConfig.ADMIN.CHALLENGE_URL}/${challenge.id}`} | ||
className={styles.challengeTitle} | ||
onClick={function onClick() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
window.location.href = `${EnvironmentConfig.ADMIN.CHALLENGE_URL}/${challenge.id}` | ||
}} | ||
> | ||
{challenge.name} | ||
</a> | ||
), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,19 +27,25 @@ interface Props { | |
onSubmitForm?: (data: FormClientsFilter) => void | ||
} | ||
|
||
const defaultValues: FormClientsFilter = { | ||
endDate: undefined, | ||
name: '', | ||
startDate: undefined, | ||
status: '1', | ||
} | ||
|
||
export const ClientsFilter: FC<Props> = (props: Props) => { | ||
const maxDate = useMemo(() => moment() | ||
.add(20, 'y') | ||
.toDate(), []) | ||
const { | ||
register, | ||
reset, | ||
handleSubmit, | ||
control, | ||
formState: { isValid }, | ||
formState: { isValid, isDirty }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
}: UseFormReturn<FormClientsFilter> = useForm({ | ||
defaultValues: { | ||
status: '1', | ||
}, | ||
defaultValues, | ||
mode: 'all', | ||
resolver: yupResolver(formClientsFilterSchema), | ||
}) | ||
|
@@ -149,6 +155,19 @@ export const ClientsFilter: FC<Props> = (props: Props) => { | |
> | ||
Filter | ||
</Button> | ||
<Button | ||
secondary | ||
onClick={function onClick() { | ||
reset(defaultValues) | ||
setTimeout(() => { | ||
onSubmit(defaultValues) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a delay duration to the |
||
}) | ||
}} | ||
size='lg' | ||
disabled={!isDirty} | ||
> | ||
Reset | ||
</Button> | ||
</div> | ||
</form> | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,18 @@ | |
} | ||
} | ||
|
||
.challengeTitle { | ||
.challengeTitleText, | ||
.challengeTitleLink { | ||
min-width: 200px; | ||
padding: 0; | ||
justify-content: flex-start; | ||
border-radius: 0; | ||
color: $body-color; | ||
line-height: 16px; | ||
white-space: break-spaces; | ||
} | ||
|
||
.challengeTitleLink { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class |
||
&:hover { | ||
color: $blue-110; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { FC, useMemo } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import { EnvironmentConfig } from '~/config' | ||
import { useWindowSize, WindowSize } from '~/libs/shared' | ||
import { Button, LinkButton, Table, type TableColumn } from '~/libs/ui' | ||
import { Sort } from '~/apps/gamification-admin/src/game-lib/pagination' | ||
|
@@ -45,13 +46,17 @@ const ChallengeTitle: FC<{ | |
review: ReviewSummary | ||
}> = props => { | ||
const goToChallenge = useEventCallback(() => { | ||
window.location.href = `https://www.topcoder.com/challenges/${props.review.legacyChallengeId}` | ||
window.location.href = `${EnvironmentConfig.ADMIN.CHALLENGE_URL}/${props.review.legacyChallengeId}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider verifying that |
||
}) | ||
|
||
return ( | ||
<LinkButton onClick={goToChallenge} className={styles.challengeTitle}> | ||
return props.review.legacyChallengeId ? ( | ||
<LinkButton onClick={goToChallenge} className={styles.challengeTitleLink}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that |
||
{props.review.challengeName} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class name |
||
</LinkButton> | ||
) : ( | ||
<span className={styles.challengeTitleText}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class name |
||
{props.review.challengeName} | ||
</span> | ||
) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,9 @@ | |
font-size: 14px; | ||
color: $black-60; | ||
} | ||
|
||
.blockBtns { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a more descriptive class name than |
||
display: flex; | ||
gap: 15px; | ||
justify-content: flex-end; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lodash library is imported but not used in the current code changes. Consider removing the import if it is not needed to avoid unnecessary dependencies.