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

feat(web): Service web contact form - Add custom fields for 'Vinnueftirlitið' #17202

Merged
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
172 changes: 170 additions & 2 deletions apps/web/components/ServiceWeb/Forms/StandardForm/StandardForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
Stack,
Text,
} from '@island.is/island-ui/core'
import { InputController } from '@island.is/shared/form-fields'
import {
CheckboxController,
InputController,
} from '@island.is/shared/form-fields'
import { sortAlpha } from '@island.is/shared/utils'
import {
ContentLanguage,
Expand All @@ -42,6 +45,7 @@ import { GET_SUPPORT_SEARCH_RESULTS_QUERY } from '@island.is/web/screens/queries
import {
FiskistofaCategories,
SjukratryggingarCategories,
VinnueftirlitidCategories,
} from '@island.is/web/screens/ServiceWeb/Forms/utils'
import { getServiceWebSearchTagQuery } from '@island.is/web/screens/ServiceWeb/utils'

Expand Down Expand Up @@ -93,6 +97,14 @@ const labels: Record<string, string> = {
malsnumer_ef_til_stadar: 'Málsnúmer (ef til staðar)',
faedingardagur_eda_kennitala_malsadila: 'Fæðingardagur/Kennitala málsaðila',
skipaskrarnumer: 'Skipaskrárnúmer',
vinnuvelanumer_kaupanda: 'Vinnuvélanúmer kaupanda',
vinnuvelanumer_seljanda: 'Vinnuvélanúmer seljanda',
vinnuvelanumer_vegna_skodunar: 'Vinnuvélanúmer vegna skoðunar',
stadsetning_taekis: 'Staðsetning tækis',
stadsetning_verkstadar: 'Staðsetning verkstaðar',
nafn_fyrirtaekis: 'Nafn fyrirtækis',
starfsstod: 'Starfsstöð',
oska_eftir_vernd_uppljostrara: 'Óska eftir vernd uppljóstrara',
}

// these should be skipped in the message itself
Expand Down Expand Up @@ -154,6 +166,35 @@ const BasicInput = ({
)
}

interface BasicCheckboxProps {
name: keyof typeof labels
label: string
}

const BasicCheckbox = ({ name, label }: BasicCheckboxProps) => {
const {
formState: { errors },
register,
} = useFormContext()

return (
<CheckboxController
id={name}
name={name}
error={errors?.[name]?.message as string}
options={[
{
label,
value: 'Já', // This value only gets sent in an email so it can be in only one locale
},
]}
// The docs tell us to spread the response of the register function even though it's return type is void
// https://react-hook-form.com/api/useformcontext/
{...(register(name) as unknown as object)}
/>
)
}

const MIN_SEARCH_QUERY_LENGTH = 1

export const StandardForm = ({
Expand Down Expand Up @@ -482,6 +523,129 @@ export const StandardForm = ({
</GridColumn>
)
break
case VinnueftirlitidCategories.NAMSKEID:
case VinnueftirlitidCategories.VINNUSLYS:
case VinnueftirlitidCategories.VINNUVELARETTINDI:
case VinnueftirlitidCategories.VINNUVERND:
case VinnueftirlitidCategories.MARKADSEFTIRLIT:
case VinnueftirlitidCategories.EKKO_OG_SAMSKIPTI:
case VinnueftirlitidCategories.LOG_OG_REGLUGERDIR:
case VinnueftirlitidCategories.LEYFI_OG_UMSAGNIR:
case VinnueftirlitidCategories.ONNUR_THJONUSTA:
fields = (
<GridColumn paddingBottom={3}>
<BasicCheckbox
name="oska_eftir_vernd_uppljostrara"
label={fn(
'oska_eftir_vernd_uppljostrara',
'label',
'Óska eftir vernd uppljóstrara',
)}
/>
</GridColumn>
)
break
case VinnueftirlitidCategories.SKRANING_OG_SKODUN_VINNUVELA:
fields = (
<>
<GridColumn paddingBottom={3}>
<BasicCheckbox
name="oska_eftir_vernd_uppljostrara"
label={fn(
'oska_eftir_vernd_uppljostrara',
'label',
'Óska eftir vernd uppljóstrara',
)}
/>
</GridColumn>
<GridColumn span="12/12" paddingBottom={3}>
<BasicInput
name="vinnuvelanumer_kaupanda"
label={fn(
'vinnuvelanumer_kaupanda',
'label',
'Vinnuvélanúmer kaupanda',
)}
/>
</GridColumn>
<GridColumn span="12/12" paddingBottom={3}>
<BasicInput
name="vinnuvelanumer_seljanda"
label={fn(
'vinnuvelanumer_seljanda',
'label',
'Vinnuvélanúmer seljanda',
)}
/>
</GridColumn>
<GridColumn span="12/12" paddingBottom={3}>
<BasicInput
name="vinnuvelanumer_vegna_skodunar"
label={fn(
'vinnuvelanumer_vegna_skodunar',
'label',
'Vinnuvélanúmer vegna skoðunar',
)}
/>
</GridColumn>
<GridColumn span="12/12" paddingBottom={3}>
<BasicInput
name="stadsetning_taekis"
label={fn('stadsetning_taekis', 'label', 'Staðsetning tækis')}
/>
</GridColumn>
</>
)
break
case VinnueftirlitidCategories.MANNVIRKJAGERD:
fields = (
<>
<GridColumn paddingBottom={3}>
<BasicCheckbox
name="oska_eftir_vernd_uppljostrara"
label={fn(
'oska_eftir_vernd_uppljostrara',
'label',
'Óska eftir vernd uppljóstrara',
)}
/>
</GridColumn>
<GridColumn span="12/12" paddingBottom={3}>
<BasicInput
name="stadsetning_verkstadar"
label={fn(
'stadsetning_verkstadar',
'label',
'Staðsetning verkstaðar',
)}
/>
</GridColumn>
</>
)
break
case VinnueftirlitidCategories.VINNUADSTADA:
fields = (
<>
<GridColumn paddingBottom={3}>
<BasicInput
name="nafn_fyrirtaekis"
requiredMessage={fn(
'nafn_fyrirtaekis',
'requiredMessage',
'Nafn fyrirtækis vantar',
)}
label={fn('nafn_fyrirtaekis', 'label', 'Nafn fyrirtækis')}
/>
</GridColumn>
<GridColumn span="12/12" paddingBottom={3}>
<BasicInput
name="starfsstod"
label={fn('starfsstod', 'label', 'Starfsstöð')}
/>
</GridColumn>
</>
)
break
default:
break
}
Expand Down Expand Up @@ -571,7 +735,11 @@ export const StandardForm = ({
const label = labels[k]
const value = values[k]

if (label && value) {
if (
label &&
((Array.isArray(value) && value.length > 0) ||
(!Array.isArray(value) && Boolean(value)))
) {
message += `${label}:\n${value}\n\n`
}

Expand Down
2 changes: 2 additions & 0 deletions apps/web/components/ServiceWeb/Forms/StandardForm/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type {
FiskistofaCategories,
SjukratryggingarCategories,
VinnueftirlitidCategories,
} from '@island.is/web/screens/ServiceWeb/Forms/utils'

export type CategoryId =
| SyslumennCategories
| SjukratryggingarCategories
| FiskistofaCategories
| VinnueftirlitidCategories

export enum SyslumennCategories {
FJOLSKYLDUMAL = '4vQ4htPOAZvzcXBcjx06SH',
Expand Down
15 changes: 15 additions & 0 deletions apps/web/screens/ServiceWeb/Forms/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ export enum FiskistofaCategories {
VEIDIHEIMILDIR = '1agbWJCHTDVfVR4yQZPaEK',
}

export enum VinnueftirlitidCategories {
NAMSKEID = '41SeTRazu0qKIixRhWpDLA',
SKRANING_OG_SKODUN_VINNUVELA = '1ulMblBQwDkfSNgh2NyKpw',
VINNUSLYS = '3VY4skpcXo7XyniStyxrVc',
VINNUVELARETTINDI = '1AkjZQc1CO6hMPXYaLSqTw',
VINNUVERND = '4Wmxb25h9R7L0kuYsz19jG',
MARKADSEFTIRLIT = '61OI7gY23wC80mRRA4yrbA',
MANNVIRKJAGERD = '7fLoJqpyojUHgdDofIpqlU',
EKKO_OG_SAMSKIPTI = '3SAlg8Xt7AKBQFrGUCTkG1',
VINNUADSTADA = '7FPsjPxRHA2aIOUXY3Xr3V',
LOG_OG_REGLUGERDIR = '7vb5yId3HMigcXEDMYN9uN',
LEYFI_OG_UMSAGNIR = '7nLIjBeO5EovoPYwINWoyv',
ONNUR_THJONUSTA = 'fdkCIdREoNlYmgkr37DTl',
}

export const filterSupportCategories = (
supportCategories: SupportCategory[] | undefined,
slug: string,
Expand Down
Loading