-
Notifications
You must be signed in to change notification settings - Fork 17
Topcoder Admin App - Add Terms Management Final fix #1133
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
base: feat/system-admin
Are you sure you want to change the base?
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
position: relative; | ||
} | ||
|
||
.blockForm { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
position: relative; | ||
} | ||
|
||
.actionButtons { | ||
display: flex; | ||
justify-content: flex-end; | ||
gap: 6px; | ||
} | ||
|
||
.dialogLoadingSpinnerContainer { | ||
position: absolute; | ||
width: 64px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
bottom: 0; | ||
height: 64px; | ||
left: 0; | ||
|
||
.spinner { | ||
background: none; | ||
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 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/** | ||
* Dialog Add Term User. | ||
*/ | ||
import { FC, useCallback } from 'react' | ||
import { | ||
Controller, | ||
ControllerRenderProps, | ||
useForm, | ||
UseFormReturn, | ||
} from 'react-hook-form' | ||
import _ from 'lodash' | ||
import classNames from 'classnames' | ||
|
||
import { yupResolver } from '@hookform/resolvers/yup' | ||
import { BaseModal, Button, LoadingSpinner } from '~/libs/ui' | ||
|
||
import { useEventCallback } from '../../hooks' | ||
import { UserTerm } from '../../models' | ||
import { FormAddTermUser } from '../../models/FormAddTermUser.model' | ||
import { formAddTermUserSchema } from '../../utils' | ||
import { FieldHandleSelect } from '../FieldHandleSelect' | ||
|
||
import styles from './DialogAddTermUser.module.scss' | ||
|
||
interface Props { | ||
className?: string | ||
open: boolean | ||
setOpen: (isOpen: boolean) => void | ||
termInfo: UserTerm | ||
isAdding: boolean | ||
doAddTermUser: ( | ||
userId: number, | ||
userHandle: string, | ||
sucess: () => void, | ||
fail: () => void, | ||
) => void | ||
} | ||
|
||
export const DialogAddTermUser: FC<Props> = (props: Props) => { | ||
const handleClose = useEventCallback(() => props.setOpen(false)) | ||
const { | ||
handleSubmit, | ||
control, | ||
reset, | ||
formState: { errors, isValid, isDirty }, | ||
}: UseFormReturn<FormAddTermUser> = useForm({ | ||
defaultValues: { | ||
handle: undefined, | ||
}, | ||
mode: 'all', | ||
resolver: yupResolver(formAddTermUserSchema), | ||
}) | ||
|
||
/** | ||
* Handle submit form event | ||
*/ | ||
const onSubmit = useCallback( | ||
(data: FormAddTermUser) => { | ||
props.doAddTermUser( | ||
data.handle?.value ?? 0, | ||
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 checking if |
||
data.handle?.label ?? '', | ||
() => { | ||
props.setOpen(false) | ||
}, | ||
() => { | ||
reset({ | ||
// eslint-disable-next-line unicorn/no-null | ||
handle: null, // only null will reset the handle field | ||
}) | ||
}, | ||
) | ||
}, | ||
[props.doAddTermUser, reset], | ||
) | ||
|
||
return ( | ||
<BaseModal | ||
allowBodyScroll | ||
blockScroll | ||
title={`Sign Terms ${props.termInfo.title}`} | ||
onClose={handleClose} | ||
open={props.open} | ||
classNames={{ | ||
modal: classNames(styles.modal), | ||
}} | ||
> | ||
<form | ||
className={classNames(styles.container, props.className)} | ||
onSubmit={handleSubmit(onSubmit)} | ||
> | ||
<div className={styles.blockForm}> | ||
<Controller | ||
name='handle' | ||
control={control} | ||
render={function render(controlProps: { | ||
field: ControllerRenderProps< | ||
FormAddTermUser, | ||
'handle' | ||
> | ||
}) { | ||
return ( | ||
<FieldHandleSelect | ||
label='Handle' | ||
value={controlProps.field.value} | ||
onChange={controlProps.field.onChange} | ||
onBlur={controlProps.field.onBlur} | ||
classNameWrapper={styles.inputField} | ||
disabled={props.isAdding} | ||
dirty | ||
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 |
||
error={_.get(errors, 'handle.message')} | ||
/> | ||
) | ||
}} | ||
/> | ||
</div> | ||
<div className={styles.actionButtons}> | ||
<Button | ||
secondary | ||
size='lg' | ||
onClick={handleClose} | ||
disabled={props.isAdding} | ||
> | ||
Close | ||
</Button> | ||
<Button | ||
type='submit' | ||
primary | ||
size='lg' | ||
disabled={props.isAdding || !isValid || !isDirty} | ||
> | ||
Sign Terms | ||
</Button> | ||
</div> | ||
|
||
{props.isAdding && ( | ||
<div className={styles.dialogLoadingSpinnerContainer}> | ||
<LoadingSpinner className={styles.spinner} /> | ||
</div> | ||
)} | ||
</form> | ||
</BaseModal> | ||
) | ||
} | ||
|
||
export default DialogAddTermUser |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as DialogAddTermUser } from './DialogAddTermUser' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,9 @@ const fetchDatas = ( | |
interface Props { | ||
label?: string | ||
className?: string | ||
classNameWrapper?: string | ||
placeholder?: string | ||
readonly value?: SelectOption | ||
readonly value?: SelectOption | 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. Consider updating the type definition for |
||
readonly onChange?: (event: SelectOption) => void | ||
readonly disabled?: boolean | ||
readonly error?: string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,9 @@ import styles from './FieldSingleSelectAsync.module.scss' | |
interface Props { | ||
label?: string | ||
className?: string | ||
classNameWrapper?: string | ||
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 description for the new |
||
placeholder?: string | ||
readonly value?: SelectOption | ||
readonly value?: SelectOption | null | ||
readonly onChange?: (event: SelectOption) => void | ||
readonly disabled?: boolean | ||
readonly loadOptions?: ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
@import '@libs/ui/styles/includes'; | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
position: relative; | ||
} | ||
|
||
.blockBtns { | ||
display: flex; | ||
gap: 15px; | ||
justify-content: flex-end; | ||
} | ||
|
||
.blockActionLoading { | ||
position: absolute; | ||
width: 64px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 64px; | ||
left: $sp-8; | ||
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 variable name instead of |
||
bottom: $sp-8; | ||
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 variable name instead of |
||
|
||
.spinner { | ||
background: none; | ||
} | ||
|
||
@include ltelg { | ||
left: $sp-4; | ||
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 variable name instead of |
||
bottom: $sp-4; | ||
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 variable name instead of |
||
} | ||
} | ||
|
||
.fieldTextContainer, | ||
.fieldTitle { | ||
grid-column: 1 / span 2; | ||
} | ||
|
||
.fieldTextContainer { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
gap: 10px; | ||
} | ||
|
||
.fieldAreaContainer { | ||
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 new class |
||
textarea { | ||
height: 200px; | ||
resize: none; | ||
} | ||
} | ||
|
||
.fieldText { | ||
width: 100%; | ||
} | ||
|
||
.btnDelete { | ||
display: flex; | ||
align-items: center; | ||
gap: 5px; | ||
|
||
strong { | ||
font-weight: bold; | ||
} | ||
} |
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.
Consider using a more descriptive class name for
.dialogLoadingSpinnerContainer
to clearly indicate its purpose or context within the dialog.