Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src-ts/lib/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface FormProps<ValueType, RequestType> {
readonly onChange?: (inputs: ReadonlyArray<FormInputModel>) => void,
readonly onSuccess?: () => void
readonly requestGenerator: (inputs: ReadonlyArray<FormInputModel>) => RequestType
readonly resetFormOnUnmount?: boolean
readonly save: (value: RequestType) => Promise<void>
}

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

useEffect(() => {
return () => {
if (props.resetFormOnUnmount) {
onReset()
}
}
}, [])

function checkIfFormIsValid(formInputFields: Array<FormInputModel>): void {
setFormInvalid(formInputFields.filter(item => !!item.error).length > 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ $error-line-height: 14px;
display: flex;
flex-direction: row;
align-items: center;
@include ltemd {
align-items: flex-start;
}
.checkbox-label {
margin-left: $space-sm;
flex: 1;
Expand Down
2 changes: 1 addition & 1 deletion src-ts/lib/form/validator-functions/validator.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function matchOther(value: InputValue, formElements?: HTMLFormControlsCol
}

export function required(value: InputValue): string | undefined {
return (value === undefined || value === '') ? 'Required' : undefined
return (value === undefined || value === '' || !(value as FileList).length) ? 'Required' : undefined
}

export function requiredIfOther(value: InputValue, formElements?: HTMLFormControlsCollection, otherFieldName?: string): string | undefined {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@import "../../../../../lib/styles/variables";
@import "../../../../../lib/styles/includes";

.wrapper {
display: flex;
flex-direction: column;
justify-content: space-between;
min-height: 100%;

.badge {
display: flex;
Expand All @@ -28,12 +31,21 @@
}
}

.actions {
.actions-wrap {
display: flex;
align-items: center;
flex-direction: column;

.actions {
display: flex;
align-items: center;

@include ltemd {
justify-content: flex-end;
}

a {
margin-right: $space-md;
a {
margin-right: $space-md;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC } from 'react'

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

Expand All @@ -13,6 +13,8 @@ export interface BadgeCreatedModalProps {

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

const isMobile: boolean = useCheckIsMobile()

function onClose(): void {
props.onClose()
}
Expand All @@ -34,17 +36,22 @@ const BadgeCreatedModal: FC<BadgeCreatedModalProps> = (props: BadgeCreatedModalP
/>
<p className={styles['badge-name']}>{props.badge.badge_name} badge has been sucessfully created.</p>
</div>
<div className={styles.actions}>
<Button
label='View'
buttonStyle='primary'
route={badgeDetailPath(props.badge.id)}
/>
<Button
label='Create a new badge'
buttonStyle='secondary'
onClick={() => window.location.reload()}
/>
<div className={styles['actions-wrap']}>
{
isMobile && <PageDivider />
}
<div className={styles.actions}>
<Button
label='View'
buttonStyle='primary'
route={badgeDetailPath(props.badge.id)}
/>
<Button
label='Create a new badge'
buttonStyle='secondary'
onClick={() => window.location.reload()}
/>
</div>
</div>
</div>
</BaseModal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const CreateBadgeForm: FC<CreateBadgeFormProps> = (props: CreateBadgeFormProps)
<Form
formDef={props.formDef}
requestGenerator={generateRequest}
resetFormOnUnmount={true}
save={saveAsync}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const createBadgeFormDef: FormDefinition = {
{
label: 'Badge Name',
name: CreateBadgeFormField.badgeName,
placeholder: 'Enter badge name',
type: 'text',
validators: [
{
Expand All @@ -62,6 +63,7 @@ export const createBadgeFormDef: FormDefinition = {
{
label: 'Badge Description',
name: CreateBadgeFormField.badgeDesc,
placeholder: 'Enter badge description, details, how to get awarded info',
type: 'textarea',
validators: [
{
Expand Down