Skip to content

Commit 5b5eef6

Browse files
authored
Merge pull request #318 from topcoder-platform/feat/GAME-82
Feat/game 82
2 parents 115468f + d69583d commit 5b5eef6

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed

src-ts/lib/form/Form.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface FormProps<ValueType, RequestType> {
3535
readonly onChange?: (inputs: ReadonlyArray<FormInputModel>) => void,
3636
readonly onSuccess?: () => void
3737
readonly requestGenerator: (inputs: ReadonlyArray<FormInputModel>) => RequestType
38+
readonly resetFormOnUnmount?: boolean
3839
readonly save: (value: RequestType) => Promise<void>
3940
}
4041

@@ -83,6 +84,14 @@ const Form: <ValueType extends any, RequestType extends any>(props: FormProps<Va
8384
inputs,
8485
])
8586

87+
useEffect(() => {
88+
return () => {
89+
if (props.resetFormOnUnmount) {
90+
onReset()
91+
}
92+
}
93+
}, [])
94+
8695
function checkIfFormIsValid(formInputFields: Array<FormInputModel>): void {
8796
setFormInvalid(formInputFields.filter(item => !!item.error).length > 0)
8897
}

src-ts/lib/form/form-groups/form-input/input-wrapper/InputWrapper.module.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ $error-line-height: 14px;
4545
display: flex;
4646
flex-direction: row;
4747
align-items: center;
48-
@include ltemd {
49-
align-items: flex-start;
50-
}
5148
.checkbox-label {
5249
margin-left: $space-sm;
5350
flex: 1;

src-ts/lib/form/validator-functions/validator.functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function matchOther(value: InputValue, formElements?: HTMLFormControlsCol
9090
}
9191

9292
export function required(value: InputValue): string | undefined {
93-
return (value === undefined || value === '') ? 'Required' : undefined
93+
return (value === undefined || value === '' || !(value as FileList).length) ? 'Required' : undefined
9494
}
9595

9696
export function requiredIfOther(value: InputValue, formElements?: HTMLFormControlsCollection, otherFieldName?: string): string | undefined {

src-ts/tools/gamification-admin/game-lib/modals/badge-created-modal/BadgeCreatedModal.module.scss

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
@import "../../../../../lib/styles/variables";
2+
@import "../../../../../lib/styles/includes";
23

34
.wrapper {
45
display: flex;
56
flex-direction: column;
7+
justify-content: space-between;
8+
min-height: 100%;
69

710
.badge {
811
display: flex;
@@ -28,12 +31,21 @@
2831
}
2932
}
3033

31-
.actions {
34+
.actions-wrap {
3235
display: flex;
33-
align-items: center;
36+
flex-direction: column;
37+
38+
.actions {
39+
display: flex;
40+
align-items: center;
41+
42+
@include ltemd {
43+
justify-content: flex-end;
44+
}
3445

35-
a {
36-
margin-right: $space-md;
46+
a {
47+
margin-right: $space-md;
48+
}
3749
}
3850
}
3951
}

src-ts/tools/gamification-admin/game-lib/modals/badge-created-modal/BadgeCreatedModal.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC } from 'react'
22

3-
import { BaseModal, Button } from '../../../../../lib'
3+
import { BaseModal, Button, PageDivider, useCheckIsMobile } from '../../../../../lib'
44
import { badgeDetailPath } from '../../../gamification-admin.routes'
55
import { GameBadge } from '../../game-badge.model'
66

@@ -13,6 +13,8 @@ export interface BadgeCreatedModalProps {
1313

1414
const BadgeCreatedModal: FC<BadgeCreatedModalProps> = (props: BadgeCreatedModalProps) => {
1515

16+
const isMobile: boolean = useCheckIsMobile()
17+
1618
function onClose(): void {
1719
props.onClose()
1820
}
@@ -34,17 +36,22 @@ const BadgeCreatedModal: FC<BadgeCreatedModalProps> = (props: BadgeCreatedModalP
3436
/>
3537
<p className={styles['badge-name']}>{props.badge.badge_name} badge has been sucessfully created.</p>
3638
</div>
37-
<div className={styles.actions}>
38-
<Button
39-
label='View'
40-
buttonStyle='primary'
41-
route={badgeDetailPath(props.badge.id)}
42-
/>
43-
<Button
44-
label='Create a new badge'
45-
buttonStyle='secondary'
46-
onClick={() => window.location.reload()}
47-
/>
39+
<div className={styles['actions-wrap']}>
40+
{
41+
isMobile && <PageDivider />
42+
}
43+
<div className={styles.actions}>
44+
<Button
45+
label='View'
46+
buttonStyle='primary'
47+
route={badgeDetailPath(props.badge.id)}
48+
/>
49+
<Button
50+
label='Create a new badge'
51+
buttonStyle='secondary'
52+
onClick={() => window.location.reload()}
53+
/>
54+
</div>
4855
</div>
4956
</div>
5057
</BaseModal>

src-ts/tools/gamification-admin/pages/create-badge/create-badge-form/CreateBadgeForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const CreateBadgeForm: FC<CreateBadgeFormProps> = (props: CreateBadgeFormProps)
4242
<Form
4343
formDef={props.formDef}
4444
requestGenerator={generateRequest}
45+
resetFormOnUnmount={true}
4546
save={saveAsync}
4647
/>
4748
)

src-ts/tools/gamification-admin/pages/create-badge/create-badge-form/create-badge-form.config.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const createBadgeFormDef: FormDefinition = {
5252
{
5353
label: 'Badge Name',
5454
name: CreateBadgeFormField.badgeName,
55+
placeholder: 'Enter badge name',
5556
type: 'text',
5657
validators: [
5758
{
@@ -62,6 +63,7 @@ export const createBadgeFormDef: FormDefinition = {
6263
{
6364
label: 'Badge Description',
6465
name: CreateBadgeFormField.badgeDesc,
66+
placeholder: 'Enter badge description, details, how to get awarded info',
6567
type: 'textarea',
6668
validators: [
6769
{

0 commit comments

Comments
 (0)