Skip to content

Commit

Permalink
UPDATE: value update
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremiahUy committed Oct 23, 2023
1 parent ee9806e commit fa4d589
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
25 changes: 5 additions & 20 deletions apps/frontend/src/components/admin/CodeList/LovCode.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import { Block, BlockProps } from 'baseui/block'
import { LabelMedium } from 'baseui/typography'
import { Block } from 'baseui/block'
import { Field, FieldProps } from 'formik'
import { Code, codelist, CodeListFormValues, ListName, LovCodeData, LovCodeRelevans, lovCodeRelevansToOptions, TemaCodeData } from '../../../services/Codelist'
import { SIZE as InputSIZE } from 'baseui/input'
import { codelist, CodeListFormValues, ListName, LovCodeData, LovCodeRelevans, lovCodeRelevansToOptions, TemaCodeData } from '../../../services/Codelist'
import { OptionList } from '../../common/Inputs'
import { temaBilder } from '../../Images'
import { StatefulTooltip } from 'baseui/tooltip'
import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { theme } from '../../../util'
import Button from '../../common/Button'
import CustomizedInput from '../../common/CustomizedInput'
import CustomizedSelect from '../../common/CustomizedSelect'
import CustomizedTextarea from '../../common/CustomizedTextarea'
import { Error } from '../../common/ModalSchema'
import { Label, Select, TextField, Textarea } from '@navikt/ds-react'

const rowBlockProps: BlockProps = {
display: 'flex',
width: '100%',
marginTop: '1rem',
alignItems: 'center',
}

export const LovCodeDataForm = () => {
return (
<div className="flex w-full mt-4 items-center flex-col">
Expand Down Expand Up @@ -54,7 +39,7 @@ export const LovCodeDataForm = () => {
<Label className="mr-4 w-1/4">
Lov ID:
</Label>
<TextField onChange={(str) => set({ lovId: (str.target as HTMLInputElement).value })} className="w-full" label="Lov ID" hideLabel />
<TextField value={data.lovId} onChange={(e) => set({ lovId: e.target.value })} className="w-full" label="Lov ID" hideLabel />
</div>

<div className="flex w-full mt-4 items-center">
Expand All @@ -63,7 +48,7 @@ export const LovCodeDataForm = () => {
</Label>
<OptionList
listName={ListName.UNDERAVDELING}
value={codelist.getCode(ListName.UNDERAVDELING, data.underavdeling)}
value={codelist.getCode(ListName.UNDERAVDELING, data.underavdeling)?.code}
onChange={(val) => set({ underavdeling: val.code })}
label={'underavdeling'}
/>
Expand All @@ -75,7 +60,7 @@ export const LovCodeDataForm = () => {
</Label>
<OptionList
listName={ListName.TEMA}
value={codelist.getCode(ListName.TEMA, data.tema) as Code | undefined}
value={codelist.getCode(ListName.TEMA, data.tema)?.code}
onChange={(val) => set({ tema: val.code })}
label={'tema'}
/>
Expand Down
5 changes: 3 additions & 2 deletions apps/frontend/src/components/common/Inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export const OptionField = (
return (
<FieldWrapper>
<Field name={props.name}>
{(p: FieldProps<string | Code>) => (
{(p: FieldProps<string>) => (
<FormControl label={<LabelWithTooltip label={props.label} tooltip={props.tooltip} />} error={p.meta.touched && p.meta.error} caption={props.caption}>
<OptionList {...props} onChange={(val) => p.form.setFieldValue(props.name, val)} value={p.field.value} />
</FormControl>
Expand All @@ -376,14 +376,15 @@ export const OptionField = (
}

export const OptionList = (
props: { label: string; clearable?: boolean; value?: Code | string; onChange: (val?: any) => void } & Or<{ options: Value }, { listName: ListName }>,
props: { label: string; value?: string; onChange: (val?: any) => void } & Or<{ options: Value }, { listName: ListName }>,
) => {
const options: Value = props.options || codelist.getParsedOptions(props.listName)
return (
<Select
label={props.label}
hideLabel
className="w-full"
value={props.value}
onChange={(e) => {
const val = e.target.value
const toSet = props.listName && val ? codelist.getCode(props.listName, val) : val
Expand Down

0 comments on commit fa4d589

Please sign in to comment.