Skip to content

Commit

Permalink
Update on Student and Staff wizard page
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahim8955 committed Aug 16, 2024
1 parent d6effbc commit 251c0d1
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 103 deletions.
3 changes: 1 addition & 2 deletions src/components/genericFields/fields/SingleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const OptionSetAutocomplete = (props: AutoCompleteProps) => {

const options =
props?.options?.optionSet?.options != null
? props?.options.optionSet?.options.map((option: { value: string; label: string }) => ({
? props?.options.optionSet?.options.map((option: { value: string, label: string }) => ({
value: option?.value,
label: option?.label
}))
Expand Down Expand Up @@ -59,7 +59,6 @@ const OptionSetAutocomplete = (props: AutoCompleteProps) => {
/>
)}
onChange={(_, value: any) => {
console.log('onchange value: ', value)
input.onChange(
props.multiple !== undefined && props.multiple !== null && Boolean(props.multiple)
? value?.length > 0
Expand Down
4 changes: 2 additions & 2 deletions src/components/staffs/AttendanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export default function AttendanceForm(): React.JSX.Element {
setNoProgramErrorMessage(null)
const programId = getDataStoreElement({ dataStores: data.dataStoreValues, elementKey: "program", key: "staff" })
const programStageId = getDataStoreElement({ dataStores: data?.dataStoreValues, elementKey: "attendance", key: "staff" })?.programStage
const studentProgramFilterConfig = getDataStoreElement({ dataStores: data?.dataStoreConfigs, elementKey: "attendance", key: "staff" })?.programStage?.filter
const staffProgramFilterConfig = getDataStoreElement({ dataStores: data?.dataStoreConfigs, elementKey: "attendance", key: "staff" })?.programStage?.filter

if (programId === undefined) {
setNoProgramErrorMessage("No programs have been configured. Please configure it before continuing !")
}
if (programId !== null && programId !== undefined) {
getProgramStages(programId, studentProgramFilterConfig)
getProgramStages(programId, staffProgramFilterConfig)
}
if (programStageId !== null && programStageId !== undefined) {
getDataElements(programStageId)
Expand Down
4 changes: 2 additions & 2 deletions src/components/staffs/EnrollmentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export default function EnrollmentForm(): React.JSX.Element {
setNoProgramErrorMessage(null)
const programId = getDataStoreElement({ dataStores: data.dataStoreValues, elementKey: "program", key: "staff" })
const programStageId = getDataStoreElement({ dataStores: data?.dataStoreValues, elementKey: "registration", key: "staff" })?.programStage
const studentProgramFilterConfig = getDataStoreElement({ dataStores: data?.dataStoreConfigs, elementKey: "registration", key: "staff" })?.programStage?.filter
const staffProgramFilterConfig = getDataStoreElement({ dataStores: data?.dataStoreConfigs, elementKey: "registration", key: "staff" })?.programStage?.filter

if (programId === undefined) {
setNoProgramErrorMessage("No programs have been configured. Please configure it before continuing !")
}

if (programId !== null && programId !== undefined) {
getProgramStages(programId,studentProgramFilterConfig)
getProgramStages(programId,staffProgramFilterConfig)
}
if (programStageId !== null && programStageId !== undefined) {
getDataElements(programStageId)
Expand Down
4 changes: 2 additions & 2 deletions src/components/staffs/TransferForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function TransferForm(): React.JSX.Element {
elementKey: 'transfer',
key: 'staff'
})?.programStage
const studentProgramFilterConfig = getDataStoreElement({
const staffProgramFilterConfig = getDataStoreElement({
dataStores: data?.dataStoreConfigs,
elementKey: 'transfer',
key: 'staff'
Expand All @@ -41,7 +41,7 @@ export default function TransferForm(): React.JSX.Element {
}

if (programId !== null && programId !== undefined) {
getProgramStages(programId, studentProgramFilterConfig)
getProgramStages(programId, staffProgramFilterConfig)
}
if (programStageId !== null && programStageId !== undefined) {
getDataElements(programStageId)
Expand Down
64 changes: 22 additions & 42 deletions src/components/students/WizardEnrollment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ export default function WizardEnrollment({ setWizardSetp }: WizardPageProps) {
{data !== undefined && data !== null && (
<div>
<Form
initialValues={{
programStage: getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'registration',
key: 'student'
})?.programStage,
grade: getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'registration',
key: 'student'
})?.grade,
section: getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'registration',
key: 'student'
})?.section,
academicYear: getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'registration',
key: 'student'
})?.academicYear
}}
onSubmit={async (value: SubmitEnrollmentValue) => {
await submit(value, data.dataStoreValues, data.dataStoreConfigs, () => {
setWizardSetp(2)
Expand All @@ -97,48 +119,6 @@ export default function WizardEnrollment({ setWizardSetp }: WizardPageProps) {
dataElementsDatas?.dataElements !== null
? dataElementsDatas?.dataElements
: []
}).map((p) => {
if (p.name === 'programStage') {
return {
...p,
defaultValue: getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'registration',
key: 'student'
})?.programStage
}
}
if (p.name === 'grade') {
return {
...p,
defaultValue: getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'registration',
key: 'student'
})?.grade
}
}
if (p.name === 'section') {
return {
...p,
defaultValue: getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'registration',
key: 'student'
})?.section
}
}
if (p.name === 'academicYear') {
return {
...p,
defaultValue: getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'registration',
key: 'student'
})?.academicYear
}
}
return p
})}
/>
<div className={style.flexBetween}>
Expand Down
47 changes: 35 additions & 12 deletions src/components/students/WizardFinalResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useFinalResultSubmit from '../../hooks/students/useFinalResultSubmit'
import style from './index.module.css'
import { Form } from 'react-final-form'
import { GroupForm } from '..'
import { IoIosArrowRoundForward } from 'react-icons/io'

interface WizardPageProps {
setWizardSetp: React.Dispatch<React.SetStateAction<number>>
Expand Down Expand Up @@ -98,8 +99,6 @@ export default function WizardFinalResult({ setWizardSetp }: WizardPageProps) {
})?.status
}}
render={({ handleSubmit, form }: any) => {
const cancelBtn = () => {}

return (
programStagesDatas?.programStages?.length > 0 && (
<form onSubmit={handleSubmit}>
Expand All @@ -113,17 +112,41 @@ export default function WizardFinalResult({ setWizardSetp }: WizardPageProps) {
dataElements: dataElementsDatas?.dataElements || []
})}
/>
<div className={style.btnContainer}>
<div>
<Button type="submit" primary loading={loadingProcessing}>
Save
</Button>
</div>
<div className={style.btnCancel}>
<Button type="button" disabled onClick={cancelBtn}>
Cancel
</Button>
<div className={style.flexBetween}>
<div className={style.flex}>
<div>
<Button type="submit" primary loading={loadingProcessing}>
Save
</Button>
</div>
<div className={style.btnCancel}>
<Button disabled type="button">
Cancel
</Button>
</div>
</div>
{getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'final-result',
key: 'student'
})?.programStage &&
getDataStoreElement({
dataStores: data.dataStoreValues,
elementKey: 'final-result',
key: 'student'
})?.status && (
<div>
<Button
primary
onClick={() => {
setWizardSetp(6)
}}
>
<IoIosArrowRoundForward style={{ fontSize: '20px' }} />
Next
</Button>
</div>
)}
</div>
</form>
)
Expand Down
16 changes: 7 additions & 9 deletions src/components/students/WizardProgram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export default function WizardProgram({ setWizardSetp }: WizardPageProps) {
{data !== undefined && data !== null && (
<div>
<Form
initialValues={{
program: getDataStoreElement({
dataStores: data?.dataStoreValues,
elementKey: 'program',
key: 'student'
})
}}
onSubmit={async (values: { program: string }) => {
await submit({
data,
Expand All @@ -50,15 +57,6 @@ export default function WizardProgram({ setWizardSetp }: WizardPageProps) {
fields={getFormFields({
programs: data.programs,
data
}).map((p) => {
return {
...p,
defaultValue: getDataStoreElement({
dataStores: data?.dataStoreValues,
elementKey: 'program',
key: 'student'
})
}
})}
/>
<div className={style.flexBetween}>
Expand Down
23 changes: 8 additions & 15 deletions src/components/students/WizardSocioEconomics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export default function WizardSocioEconomics({ setWizardSetp }: WizardPageProps)
{data !== undefined && data !== null && (
<div>
<Form
initialValues={{
programStage: getDataStoreElement({
dataStores: data?.dataStoreValues,
elementKey: 'socio-economics',
key: 'student'
})?.programStage
}}
onSubmit={async (values: { programStage: string }) => {
await submit(
{ programStage: values?.programStage },
Expand All @@ -82,21 +89,7 @@ export default function WizardSocioEconomics({ setWizardSetp }: WizardPageProps)
<GroupForm
disabled={false}
name="socio-economics"
fields={getFormFields(data, programStagesDatas.programStages).map(
(p) => {
if (p.name === 'programStage') {
return {
...p,
defaultValue: getDataStoreElement({
dataStores: data?.dataStoreValues,
elementKey: 'socio-economics',
key: 'student'
})?.programStage
}
}
return p
}
)}
fields={getFormFields(data, programStagesDatas.programStages)}
/>
<div className={style.flexBetween}>
<div className={style.flex}>
Expand Down
Loading

0 comments on commit 251c0d1

Please sign in to comment.