Skip to content
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

fix(ojoi): Update form context #16147

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../../lib/constants'
import { getCommitteeAnswers, getEmptyMember } from '../../lib/utils'
import set from 'lodash/set'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -20,6 +21,8 @@ export const AddCommitteeMember = ({ applicationId }: Props) => {
applicationId,
})

const { setValue } = useFormContext()

const onAddCommitteeMember = () => {
const { signature, currentAnswers } = getCommitteeAnswers(
structuredClone(application.answers),
Expand All @@ -37,6 +40,8 @@ export const AddCommitteeMember = ({ applicationId }: Props) => {
withExtraMember,
)

setValue(InputFields.signature.committee, withExtraMember)

updateApplication(updatedAnswers)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../../lib/constants'
import { getEmptyMember, getRegularAnswers } from '../../lib/utils'
import set from 'lodash/set'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -21,6 +22,8 @@ export const AddRegularMember = ({ applicationId, signatureIndex }: Props) => {
applicationId,
})

const { setValue } = useFormContext()

const onAddMember = () => {
const { signature, currentAnswers } = getRegularAnswers(
structuredClone(application.answers),
Expand All @@ -47,6 +50,8 @@ export const AddRegularMember = ({ applicationId, signatureIndex }: Props) => {
updatedRegularSignature,
)

setValue(InputFields.signature.regular, updatedRegularSignature)

updateApplication(updatedAnswers)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MAXIMUM_REGULAR_SIGNATURE_COUNT,
ONE,
} from '../../lib/constants'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -26,6 +27,8 @@ export const AddRegularSignature = ({ applicationId }: Props) => {
applicationId,
})

const { setValue } = useFormContext()

const onAddInstitution = () => {
const { signature, currentAnswers } = getRegularAnswers(
structuredClone(application.answers),
Expand All @@ -37,12 +40,16 @@ export const AddRegularSignature = ({ applicationId }: Props) => {
DEFAULT_REGULAR_SIGNATURE_MEMBER_COUNT,
)?.pop()

const updatedSignature = [...signature, newSignature]

const updatedAnswers = set(
currentAnswers,
InputFields.signature.regular,
[...signature, newSignature],
updatedSignature,
)

setValue(InputFields.signature.regular, updatedSignature)

updateApplication(updatedAnswers)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SignatureMember } from './Member'
import set from 'lodash/set'
import * as styles from './Signatures.css'
import * as z from 'zod'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -27,6 +28,8 @@ export const Chairman = ({ applicationId, member }: Props) => {
applicationId,
})

const { setValue } = useFormContext()

const handleChairmanChange = (value: string, key: keyof MemberProperties) => {
const { signature, currentAnswers } = getCommitteeAnswers(
application.answers,
Expand Down Expand Up @@ -57,6 +60,8 @@ export const Chairman = ({ applicationId, member }: Props) => {
updatedCommitteeSignature,
)

setValue(InputFields.signature.committee, updatedCommitteeSignature)

return updatedSignatures
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { memberItemSchema } from '../../lib/dataSchema'
import { SignatureMember } from './Member'
import * as z from 'zod'
import { RemoveCommitteeMember } from './RemoveComitteeMember'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -33,6 +34,8 @@ export const CommitteeMember = ({
applicationId,
})

const { setValue } = useFormContext()

const handleMemberChange = (
value: string,
key: keyof MemberProperties,
Expand Down Expand Up @@ -77,6 +80,8 @@ export const CommitteeMember = ({
updatedCommitteeSignature,
)

setValue(InputFields.signature.committee, updatedCommitteeSignature)

return updatedSignatures
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { z } from 'zod'
import { signatureInstitutionSchema } from '../../lib/dataSchema'
import { RemoveRegularSignature } from './RemoveRegularSignature'
import { useFormContext } from 'react-hook-form'
type Props = {
applicationId: string
type: SignatureType
Expand All @@ -49,6 +50,8 @@ export const InstitutionSignature = ({
applicationId,
})

const { setValue } = useFormContext()

const handleInstitutionChange = (
value: string,
key: SignatureInstitutionKeys,
Expand Down Expand Up @@ -88,6 +91,8 @@ export const InstitutionSignature = ({
updatedRegularSignature,
)

setValue(InputFields.signature[type], updatedRegularSignature)

return updatedSignatures
}

Expand All @@ -114,6 +119,8 @@ export const InstitutionSignature = ({
},
)

setValue(InputFields.signature[type], updatedCommitteeSignature)

return updatedCommitteeSignature
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { memberItemSchema } from '../../lib/dataSchema'
import { SignatureMember } from './Member'
import * as z from 'zod'
import { RemoveRegularMember } from './RemoveRegularMember'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -36,6 +37,8 @@ export const RegularMember = ({
applicationId,
})

const { setValue } = useFormContext()

const handleMemberChange = (
value: string,
key: keyof MemberProperties,
Expand Down Expand Up @@ -84,6 +87,8 @@ export const RegularMember = ({
updatedRegularSignature,
)

setValue(InputFields.signature.regular, updatedRegularSignature)

return updatedSignatures
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MINIMUM_COMMITTEE_SIGNATURE_MEMBER_COUNT } from '../../lib/constants'
import set from 'lodash/set'
import * as styles from './Signatures.css'
import { getCommitteeAnswers, isCommitteeSignature } from '../../lib/utils'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -19,6 +20,8 @@ export const RemoveCommitteeMember = ({
applicationId,
})

const { setValue } = useFormContext()

const onRemoveMember = () => {
const { currentAnswers, signature } = getCommitteeAnswers(
application.answers,
Expand All @@ -36,6 +39,8 @@ export const RemoveCommitteeMember = ({
updatedCommitteeSignature,
)

setValue(InputFields.signature.committee, updatedCommitteeSignature)

updateApplication(updatedAnswers)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MINIMUM_REGULAR_SIGNATURE_MEMBER_COUNT } from '../../lib/constants'
import set from 'lodash/set'
import * as styles from './Signatures.css'
import { getRegularAnswers } from '../../lib/utils'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -21,6 +22,8 @@ export const RemoveRegularMember = ({
applicationId,
})

const { setValue } = useFormContext()

const onRemoveMember = () => {
const { currentAnswers, signature } = getRegularAnswers(application.answers)

Expand All @@ -45,6 +48,8 @@ export const RemoveRegularMember = ({
updatedRegularSignature,
)

setValue(InputFields.signature.regular, updatedRegularSignature)

updateApplication(updatedAnswers)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getValueViaPath } from '@island.is/application/core'
import { InputFields } from '../../lib/types'
import { isRegularSignature } from '../../lib/utils'
import set from 'lodash/set'
import { useFormContext } from 'react-hook-form'

type Props = {
applicationId: string
Expand All @@ -18,6 +19,8 @@ export const RemoveRegularSignature = ({
applicationId,
})

const { setValue } = useFormContext()

const onRemove = () => {
const currentAnswers = structuredClone(application.answers)
const signature = getValueViaPath(
Expand All @@ -36,6 +39,8 @@ export const RemoveRegularSignature = ({
updatedRegularSignature,
)

setValue(InputFields.signature.regular, updatedRegularSignature)

updateApplication(updatedSignatures)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
DEFAULT_COMMITTEE_SIGNATURE_MEMBER_COUNT,
DEFAULT_REGULAR_SIGNATURE_COUNT,
DEFAULT_REGULAR_SIGNATURE_MEMBER_COUNT,
OJOI_INPUT_HEIGHT as OJOI_INPUT_HEIGHT,
OJOI_INPUT_HEIGHT,
SignatureTypes,
} from '../lib/constants'
import { useApplication } from '../hooks/useUpdateApplication'
Expand Down
Loading