Skip to content

Commit

Permalink
fix(regulations-admin): date format signature, remove self affect, di…
Browse files Browse the repository at this point in the history
…sclaimer text (#16288)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thordurhhh and kodiakhq[bot] authored Oct 7, 2024
1 parent 18373d4 commit dcd0002
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { downloadUrl } from '../utils/files'
import { DownloadDraftButton } from './DownloadDraftButton'
import { useLocale } from '@island.is/localization'
import { useS3Upload } from '../utils/dataHooks'
import { formatDate } from '../utils/formatAmendingUtils'

// ---------------------------------------------------------------------------

Expand All @@ -31,7 +32,6 @@ const defaultSignatureText = `
` as HTMLText

const getDefaultSignatureText = (
dateFormatter: (date: Date, str?: string) => string,
/** The ministry of the author-type user that created the RegulationDraft */
authorMinistry?: PlainText,
) => {
Expand All @@ -41,7 +41,7 @@ const getDefaultSignatureText = (
const defaultMinister = '⸻ráðherra'

return defaultSignatureText
.replace('{dags}', dateFormatter(new Date(), 'dd. MMMM yyyy'))
.replace('{dags}', formatDate(new Date()))
.replace('{ministry}', authorMinistry || defaultMinistry)
.replace('{minister}', authorMinister || defaultMinister) as HTMLText
}
Expand Down Expand Up @@ -159,7 +159,7 @@ export const EditSignature = () => {
draftId={draft.id}
value={
draft.signatureText.value ||
getDefaultSignatureText(formatDateFns, draft.ministry.value)
getDefaultSignatureText(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 @@ -44,6 +44,9 @@ export const ImpactBaseSelection = ({
if (loading) {
return null
}
if (!mentionedOptions.length) {
return null
}
return (
<Select
size="sm"
Expand Down
2 changes: 1 addition & 1 deletion libs/portals/admin/regulations-admin/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export const impactMsgs = defineMessages({
regExplainer: {
id: 'ap.regulations-admin:draft-impactedreg-explainer',
defaultMessage:
'ATH: Einungis er hægt að breyta reglugerðum sem minnst er á með skýrum hætti í texta reglugerðarinnar.',
'ATH: Sé ætlunin að breyta annarri reglugerð, þarf að minnast á þá reglugerð með skýrum hætti í þessari stofnreglugerð.',
},
regExplainer_editLink: {
id: 'ap.regulations-admin:draft-impactedreg-editlink',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import {
GroupedDraftImpactForms,
RegDraftForm,
} from '../state/types'
import format from 'date-fns/format'
import is from 'date-fns/locale/is'
import compact from 'lodash/compact'
import flatten from 'lodash/flatten'
import uniq from 'lodash/uniq'
import {
allSameDay,
extractArticleTitleDisplay,
formatDate,
getTextWithSpaces,
groupElementsByArticleTitleFromDiv,
hasAnyChange,
Expand Down Expand Up @@ -52,18 +51,6 @@ const formatAffectedAndPlaceAffectedAtEnd = (
return ''
}

const formatDate = (date: Date) => {
const newDate = new Date(date)
if (newDate) {
const formattedDate = format(new Date(date), 'dd. MMMM yyyy', {
locale: is,
})
return formattedDate.replace(/^0+/, '') // Remove leading zeros
} else {
return ''
}
}

const extractArticleNumber = (str: string): number | null => {
const match = str.match(/(\d+)\. gr/)
return match ? parseInt(match[1], 10) : null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import isSameDay from 'date-fns/isSameDay'
import format from 'date-fns/format'
import is from 'date-fns/locale/is'
import { HTMLText, asDiv } from '@island.is/regulations'

export const groupElementsByArticleTitleFromDiv = (
Expand Down Expand Up @@ -114,3 +116,15 @@ export const updateAppendixWording = (input: string): string => {
return match
})
}

export const formatDate = (date: Date) => {
const newDate = new Date(date)
if (newDate) {
const formattedDate = format(new Date(date), 'dd. MMMM yyyy', {
locale: is,
})
return formattedDate.replace(/^0+/, '') // Remove leading zeros
} else {
return ''
}
}
10 changes: 5 additions & 5 deletions libs/portals/admin/regulations-admin/src/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ export const useAffectedRegulations = (
data,
)

options.push({
type: selfType,
value: 'self',
label: selfAffectingText,
})
// options.push({
// type: selfType,
// value: 'self',
// label: selfAffectingText,
// })

return options
}, [selfType, mentioned, data, notFoundText, selfAffectingText, repealedText])
Expand Down

0 comments on commit dcd0002

Please sign in to comment.