Skip to content

Commit

Permalink
feat(regulations-admin): ministry basic + bugfixes (#16042)
Browse files Browse the repository at this point in the history
* Add ministry to basic screen + minor bugfixes

* Remove console log

* Minor refactor

* cleanup

* cleanup

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thordurhhh and kodiakhq[bot] authored Sep 18, 2024
1 parent 825530d commit 378e8a9
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class RegulationDocumentsController {
comments: draftRegulation.comments,
name: draftRegulation.name,
publishedDate: draftRegulation.idealPublishDate,
ministry: draftRegulation.ministry,
}

const documentResponse =
Expand Down
55 changes: 45 additions & 10 deletions libs/portals/admin/regulations-admin/src/components/EditBasics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
Button,
AlertMessage,
AlertBanner,
Select,
} from '@island.is/island-ui/core'
import { EditorInput } from './EditorInput'
import { editorMsgs as msg, errorMsgs } from '../lib/messages'
import { editorMsgs as msg, errorMsgs, m } from '../lib/messages'
import { useLocale } from '@island.is/localization'
import { Appendixes } from './Appendixes'
import { MagicTextarea } from './MagicTextarea'
Expand All @@ -32,7 +33,7 @@ const updateText =

export const EditBasics = () => {
const t = useLocale().formatMessage
const { draft, actions } = useDraftingState()
const { draft, actions, ministries } = useDraftingState()
const [editorKey, setEditorKey] = useState('initial')
const [titleError, setTitleError] = useState<string | undefined>(undefined)
const [hasUpdated, setHasUpdated] = useState<boolean>(false)
Expand Down Expand Up @@ -162,13 +163,15 @@ export const EditBasics = () => {
label={t(msg.text)}
startExpanded={startTextExpanded}
>
<Box marginBottom={3}>
<AlertBanner
description={t(msg.diffPrecisionWarning)}
variant="info"
dismissable
/>
</Box>
{draft.type.value === RegulationDraftTypes.amending ? (
<Box marginBottom={3}>
<AlertBanner
description={t(msg.diffPrecisionWarning)}
variant="info"
dismissable
/>
</Box>
) : undefined}
<Box marginBottom={3}>
<EditorInput
key={editorKey} // Force re-render of TinyMCE
Expand Down Expand Up @@ -224,7 +227,7 @@ export const EditBasics = () => {
<Divider />
{' '}
</Box>
{draft.signedDocumentUrl.value && (
{draft.signedDocumentUrl.value ? (
<Box marginBottom={[4, 4, 6]}>
<EditorInput
label={t(msg.signatureText)}
Expand All @@ -234,6 +237,38 @@ export const EditBasics = () => {
readOnly
/>
</Box>
) : (
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(msg.selectMinistry)}
options={[
{
label: t(msg.selectMinistry),
value: '',
},
...ministries.map((ministry) => ({
value: ministry.name,
label: ministry.name,
})),
].filter((item) => item.label)}
required={false}
onChange={(option) => actions.setMinistry(option?.value)}
backgroundColor="white"
/>
)
)}
</AccordionItem>
</Accordion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const EditSignature = () => {
draftId={draft.id}
value={
draft.signatureText.value ||
getDefaultSignatureText(formatDateFns)
getDefaultSignatureText(formatDateFns, draft.ministry.value)
}
onChange={(text) => updateState('signatureText', text)}
required={!!draft.signatureText.required}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export const EditCancellation = (props: EditCancellationProp) => {
<ImpactModalTitle
impact={activeCancellation}
name={activeCancellation.name}
title={activeCancellation.regTitle}
title={
activeCancellation.name === 'self'
? 'stofnreglugerð'
: activeCancellation.regTitle
}
type={'cancel'}
minDate={minDate}
tag={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,11 @@ export const EditChange = (props: EditChangeProp) => {
>
<ImpactModalTitle
type="edit"
title={activeChange.regTitle}
title={
activeChange.name === 'self'
? 'stofnreglugerð'
: activeChange.regTitle
}
name={activeChange.name}
impact={activeChange}
minDate={readOnly ? activeChange.date.value : minDate}
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 @@ -135,6 +135,10 @@ export const actionHandlers: {
}
},

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

SET_IMPACT: (state, { impactId }) => {
if (impactId) {
Object.entries(state.draft.impacts).forEach(([key, impacts]) => {
Expand Down
4 changes: 4 additions & 0 deletions libs/portals/admin/regulations-admin/src/state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ export type Action =
action?: 'add' | 'delete'
value: LawChapterSlug
}
| {
type: 'SET_MINISTRY'
value?: PlainText
}
| ({
type: 'UPDATE_PROP'
} & FieldNameValuePair)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ReactNode,
} from 'react'
import { useMutation, gql } from '@apollo/client'
import { LawChapterSlug, toISODate } from '@island.is/regulations'
import { LawChapterSlug, PlainText, toISODate } from '@island.is/regulations'
import { useNavigate } from 'react-router-dom'
import { RegulationDraftTypes, Step, StepNames } from '../types'
import { useLocale } from '@island.is/localization'
Expand Down Expand Up @@ -252,6 +252,10 @@ const useMakeDraftingState = (inputs: StateInputs) => {
dispatch({ type: 'APPENDIX_ADD' })
},

setMinistry: (value?: PlainText) => {
dispatch({ type: 'SET_MINISTRY', value })
},

updateLawChapterProp: (
action: 'add' | 'delete',
value: LawChapterSlug,
Expand Down
1 change: 1 addition & 0 deletions libs/regulations/src/lib/types-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export type RegulationPdfInput = {
comments: HTMLText
name?: RegName
publishedDate?: ISODate
ministry?: string
}

/** API response from regulation API */
Expand Down

0 comments on commit 378e8a9

Please sign in to comment.