Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thordurhhh committed Sep 18, 2024
1 parent 9f20295 commit 7ccd707
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
67 changes: 38 additions & 29 deletions libs/portals/admin/regulations-admin/src/components/EditBasics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Select,
} from '@island.is/island-ui/core'
import { EditorInput } from './EditorInput'
import { editorMsgs as msg, errorMsgs, m } from '../lib/messages'
import { editorMsgs as msg, errorMsgs, m, editorMsgs } from '../lib/messages'
import { useLocale } from '@island.is/localization'
import { Appendixes } from './Appendixes'
import { MagicTextarea } from './MagicTextarea'
Expand Down Expand Up @@ -238,34 +238,43 @@ export const EditBasics = () => {
/>
</Box>
) : (
<Select
size="sm"
label={t(m.regulationAdminMinistries)}
name="setMinistry"
isSearchable
value={
draft.ministry.value
? {
value: draft.ministry.value,
label: draft.ministry.value,
}
: undefined
}
placeholder={t(m.regulationAdminMinistries)}
options={ministries.map((ministry) => ({
value: ministry.name,
label: ministry.name,
}))}
required={false}
onChange={(option) => actions.setMinistry(option?.value)}
backgroundColor="white"
hasError={
draft.ministry.showError &&
!!draft.ministry.error &&
t(draft.ministry.error) !== t(errorMsgs.fieldRequired)
}
errorMessage={draft.ministry.error && t(draft.ministry.error)}
/>
ministries.length > 0 &&
!draft.signatureText.value && (
<Select
size="sm"
label={t(m.regulationAdminMinistries)}
name="setMinistry"
isSearchable
value={
draft.ministry.value
? {
value: draft.ministry.value,
label: draft.ministry.value,
}
: undefined
}
placeholder={t(editorMsgs.selectMinistry)}
options={[
{
label: t(editorMsgs.selectMinistry),
value: undefined,
},
...ministries.map((ministry) => ({
value: ministry.name,
label: ministry.name,
})),
]}
required={false}
onChange={(option) => actions.setMinistry(option?.value)}
backgroundColor="white"
hasError={
draft.ministry.showError &&
!!draft.ministry.error &&
!!draft.ministry.value
}
errorMessage={draft.ministry.error && t(draft.ministry.error)}
/>
)
)}
</AccordionItem>
</Accordion>
Expand Down
4 changes: 4 additions & 0 deletions libs/portals/admin/regulations-admin/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ export const editorMsgs = defineMessages({
defaultMessage:
'Vakin er athygli á því að kerfið útbýr tillögu að breytingareglugerð sem starfsmaður þarf að rýna gaumgæfilega áður en haldið er áfram. Ekki er öruggt að inngangsliðir og efnisákvæði færist réttilega inn í breytingareglugerðina.',
},
selectMinistry: {
id: 'ap.regulations-admin:select-ministry',
defaultMessage: 'Veldu ráðuneyti',
},
})

export const impactMsgs = defineMessages({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,7 @@ export const actionHandlers: {
},

SET_MINISTRY: (state, { value }) => {
if (value) {
updateFieldValue(state.draft.ministry, value)
} else {
updateFieldValue(state.draft.ministry, undefined)
}
updateFieldValue(state.draft.ministry, value ?? undefined)
},

SET_IMPACT: (state, { impactId }) => {
Expand Down

0 comments on commit 7ccd707

Please sign in to comment.