Skip to content

Commit fd20e71

Browse files
committed
init create badge form
1 parent 143ca20 commit fd20e71

File tree

6 files changed

+69
-25
lines changed

6 files changed

+69
-25
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { FC } from 'react'
2+
3+
import { BaseModal } from '../../../../../lib'
4+
5+
export interface BadgeCreatedModalProps {
6+
isOpen: boolean
7+
onClose: () => void
8+
}
9+
10+
const BadgeCreatedModal: FC<BadgeCreatedModalProps> = (props: BadgeCreatedModalProps) => {
11+
12+
function onClose(): void {
13+
props.onClose()
14+
}
15+
16+
return (
17+
<BaseModal
18+
onClose={onClose}
19+
open={props.isOpen}
20+
size='md'
21+
title={`Badge created`}
22+
>
23+
24+
</BaseModal>
25+
)
26+
}
27+
28+
export default BadgeCreatedModal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as BadgeCreatedModal } from './BadgeCreatedModal'

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { FC } from 'react'
1+
import { Dispatch, FC, SetStateAction, useState } from 'react'
22

33
import { Breadcrumb, BreadcrumbItemModel, ContentLayout } from '../../../../lib'
44
import { useGamificationBreadcrumb } from '../../game-lib'
5+
import { CreateBadgeForm, createBadgeFormDef } from './create-badge-form'
6+
import { BadgeCreatedModal } from '../../game-lib/modals/badge-created-modal'
57

68
import styles from './CreateBadgePage.module.scss'
79

@@ -14,17 +16,28 @@ const CreateBadgePage: FC = () => {
1416
},
1517
])
1618

19+
const [showBadgeCreatedModal, setShowBadgeCreatedModal]: [boolean, Dispatch<SetStateAction<boolean>>]
20+
= useState<boolean>(false)
21+
22+
function onSave() {
23+
setShowBadgeCreatedModal(true)
24+
}
25+
1726
return (
1827
<ContentLayout
19-
contentClass={styles['contentLayout']}
20-
outerClass={styles['contentLayout-outer']}
21-
innerClass={styles['contentLayout-inner']}
2228
title='Create Badge'
2329
>
2430
<Breadcrumb items={breadcrumb} />
2531
<div className={styles.container}>
26-
32+
<CreateBadgeForm
33+
formDef={createBadgeFormDef}
34+
onSave={onSave}
35+
/>
2736
</div>
37+
<BadgeCreatedModal
38+
isOpen={showBadgeCreatedModal}
39+
onClose={() => setShowBadgeCreatedModal(false)}
40+
/>
2841
</ContentLayout>
2942
)
3043
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { FC, useContext } from 'react'
1+
import { Dispatch, FC, SetStateAction, useState } from 'react'
22

3-
import { Form, FormDefinition, formGetInputModel, FormInputModel, profileContext, ProfileContextData } from '../../../../../lib'
3+
import { Form, FormDefinition, formGetInputModel, FormInputModel } from '../../../../../lib'
44

55
import { CreateBadgeFormField } from './create-badge-form.config'
66
import { CreateBadgeRequest } from './create-badge-functions'
77
import { createBadgeSubmitRequestAsync } from './create-badge-functions/create-badge-store'
8+
import { createBadgeFormDef } from './create-badge-form.config'
9+
810
import styles from './CreateBadgeForm.module.scss'
911

1012
export interface CreateBadgeFormProps {
@@ -13,21 +15,25 @@ export interface CreateBadgeFormProps {
1315
}
1416

1517
const CreateBadgeForm: FC<CreateBadgeFormProps> = (props: CreateBadgeFormProps) => {
18+
19+
// createBadgeFormDef.buttons.primaryGroup[0].onClick = (e) => { console.log('save btn click', e); e.preventDefault() }
1620

17-
const { profile }: ProfileContextData = useContext(profileContext)
1821

1922
function generateRequest(inputs: ReadonlyArray<FormInputModel>): CreateBadgeRequest {
2023
const badgeName: string = formGetInputModel(inputs, CreateBadgeFormField.badgeName).value as string
2124
const badgeDesc: string = formGetInputModel(inputs, CreateBadgeFormField.badgeDesc).value as string
2225
const badgeActive: string = formGetInputModel(inputs, CreateBadgeFormField.badgeActive).value as string
26+
2327
return {
24-
badgeActive,
25-
badgeName,
26-
badgeDesc,
28+
badgeActive,
29+
badgeName,
30+
badgeDesc,
2731
}
2832
}
2933

3034
async function saveAsync(request: CreateBadgeRequest): Promise<void> {
35+
console.log('saveAsync', request)
36+
3137
return createBadgeSubmitRequestAsync(request)
3238
.then(() => {
3339
props.onSave()
@@ -38,7 +44,6 @@ const CreateBadgeForm: FC<CreateBadgeFormProps> = (props: CreateBadgeFormProps)
3844
<>
3945
<Form
4046
formDef={props.formDef}
41-
formValues={profile}
4247
requestGenerator={generateRequest}
4348
save={saveAsync}
4449
/>

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FormDefinition, validatorRequired, IconOutline, RadioButton } from '../../../../../lib'
1+
import { FormDefinition, validatorRequired, IconOutline } from '../../../../../lib'
22

33
export enum CreateBadgeFormField {
44
badgeActive = 'badgeActive',
@@ -13,6 +13,7 @@ export const createBadgeFormDef: FormDefinition = {
1313
buttonStyle: 'primary',
1414
isSubmit: true,
1515
label: 'Save Badge',
16+
onClick: (e) => { },
1617
size: 'lg',
1718
type: 'submit',
1819
},
@@ -22,14 +23,19 @@ export const createBadgeFormDef: FormDefinition = {
2223
buttonStyle: 'icon-bordered',
2324
size: 'lg',
2425
icon: IconOutline.ChevronLeftIcon,
25-
route: `/gamification-admin`
26-
26+
route: '/gamification-admin'
27+
2728
},
2829
]
2930
},
3031
groups: [
3132
{
3233
inputs: [
34+
// {
35+
// label: 'Activate',
36+
// name: CreateBadgeFormField.badgeActive,
37+
// type: 'checkbox',
38+
// },
3339
{
3440
label: 'Badge Name',
3541
name: CreateBadgeFormField.badgeName,
@@ -49,16 +55,6 @@ export const createBadgeFormDef: FormDefinition = {
4955
validator: validatorRequired,
5056
},
5157
],
52-
},
53-
{
54-
label: 'Activate',
55-
name: CreateBadgeFormField.badgeActive,
56-
type: 'checkbox',
57-
validators: [
58-
{
59-
validator: validatorRequired,
60-
},
61-
],
6258
}
6359
],
6460
},

src-ts/tools/gamification-admin/pages/create-badge/create-badge-form/create-badge-functions/create-badge-store/create-badge.store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { xhrPostAsync } from '../../../../../../../lib'
44
import { CreateBadgeRequest } from './create-badge-request.model'
55

66
export async function submitRequestAsync(request: CreateBadgeRequest): Promise<void> {
7+
console.log('submitRequestAsync', request)
78
const url: string = `${EnvironmentConfig.API.V5}/gamification/badges`
89
await xhrPostAsync(url, request)
910
}

0 commit comments

Comments
 (0)