From 1d82f211b7934b39e2f5bddf9b3e5b39d48efc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9E=C3=B3r=C3=B0ur=20H?= Date: Mon, 29 Apr 2024 19:21:42 +0000 Subject: [PATCH 1/7] chore(housing-benefits): Add housing benefits scope (#14597) * Add housing benefits scope * Update scope-housing-benefits.ts --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../seeders/data/scope-housing-benefits.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 libs/auth-api-lib/seeders/data/scope-housing-benefits.ts diff --git a/libs/auth-api-lib/seeders/data/scope-housing-benefits.ts b/libs/auth-api-lib/seeders/data/scope-housing-benefits.ts new file mode 100644 index 000000000000..f3ed6b773a38 --- /dev/null +++ b/libs/auth-api-lib/seeders/data/scope-housing-benefits.ts @@ -0,0 +1,11 @@ +import { compose, createScope } from './helpers' + +export const up = compose( + createScope({ + name: '@hms.is/housing-benefits', + displayName: 'Húsnæðisbætur', + description: 'Bakendascope fyrir húsnæðisbætur', + addToClients: ['@island.is/clients/api'], + accessControlled: false, + }), +) From 3c2ff173138b886058245251550e8040cd62b09d Mon Sep 17 00:00:00 2001 From: unakb Date: Mon, 29 Apr 2024 19:32:13 +0000 Subject: [PATCH 2/7] fix(j-s): Zod error when street number is null (#14639) * fix(j-s): Allow null for street number * fix(j-s): Zod street number * fix(j-s): Tests * Update police.service.ts * Update getPoliceCaseInfo.spec.ts --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/app/modules/police/police.service.ts | 18 +++++++++--------- .../police/test/getPoliceCaseInfo.spec.ts | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/police/police.service.ts b/apps/judicial-system/backend/src/app/modules/police/police.service.ts index 461c672944b1..6dbdbe7c8ffe 100644 --- a/apps/judicial-system/backend/src/app/modules/police/police.service.ts +++ b/apps/judicial-system/backend/src/app/modules/police/police.service.ts @@ -62,9 +62,9 @@ const getChapter = (category?: string): number | undefined => { } const formatCrimeScenePlace = ( - street?: string, - streetNumber?: string, - municipality?: string, + street?: string | null, + streetNumber?: string | null, + municipality?: string | null, ) => { if (!street && !municipality) { return '' @@ -102,9 +102,9 @@ export class PoliceService { upprunalegtMalsnumer: z.string(), licencePlate: z.optional(z.string()), gotuHeiti: z.optional(z.string()), - gotuNumer: z.optional(z.string()), - sveitafelag: z.optional(z.string()), - postnumer: z.optional(z.string()), + gotuNumer: z.string().nullish(), + sveitafelag: z.string().nullish(), + postnumer: z.string().nullish(), }) private responseStructure = z.object({ malsnumer: z.string(), @@ -336,9 +336,9 @@ export class PoliceService { vettvangur?: string brotFra?: string licencePlate?: string - gotuHeiti?: string - gotuNumer?: string - sveitafelag?: string + gotuHeiti?: string | null + gotuNumer?: string | null + sveitafelag?: string | null }) => { const policeCaseNumber = info.upprunalegtMalsnumer diff --git a/apps/judicial-system/backend/src/app/modules/police/test/getPoliceCaseInfo.spec.ts b/apps/judicial-system/backend/src/app/modules/police/test/getPoliceCaseInfo.spec.ts index db80aab35b8b..06f57191b081 100644 --- a/apps/judicial-system/backend/src/app/modules/police/test/getPoliceCaseInfo.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/police/test/getPoliceCaseInfo.spec.ts @@ -106,6 +106,7 @@ describe('PoliceController - Get police case info', () => { upprunalegtMalsnumer: '007-2020-000103', brotFra: '2021-02-23T13:17:00', gotuHeiti: 'Teststígur', + gotuNumer: null, sveitafelag: 'Testbær', licencePlate: 'CDE-123', }, @@ -113,6 +114,7 @@ describe('PoliceController - Get police case info', () => { upprunalegtMalsnumer: '007-2020-000057', brotFra: '2021-02-23T13:17:00', gotuHeiti: 'Teststígur', + sveitafelag: null, }, ], }), From 1f777926e5492ef4ba893a1e416c7e2f59bba03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Tue, 30 Apr 2024 11:05:09 +0000 Subject: [PATCH 3/7] feat(j-s): Send Names to Robot (#14642) --- .../app/modules/case/internalCase.service.ts | 4 +++ ...liverAssignedRolesToCourtOfAppeals.spec.ts | 28 ++++++++++++++++--- .../src/app/modules/court/court.service.ts | 12 ++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts index a78cb6307567..2deede784006 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts @@ -772,9 +772,13 @@ export class InternalCaseService { theCase.id, theCase.appealCaseNumber, theCase.appealAssistant?.nationalId, + theCase.appealAssistant?.name, theCase.appealJudge1?.nationalId, + theCase.appealJudge1?.name, theCase.appealJudge2?.nationalId, + theCase.appealJudge2?.name, theCase.appealJudge3?.nationalId, + theCase.appealJudge3?.name, ) .then(() => ({ delivered: true })) .catch((reason) => { diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAssignedRolesToCourtOfAppeals.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAssignedRolesToCourtOfAppeals.spec.ts index af2841de798b..656efbcde734 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAssignedRolesToCourtOfAppeals.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAssignedRolesToCourtOfAppeals.spec.ts @@ -24,9 +24,13 @@ describe('InternalCaseController - Deliver assigned roles to court of appeals', const appealJudge2Id = uuid() const appealJudge3Id = uuid() const appealAssistantNationalId = uuid() + const appealAssistantName = uuid() const appealJudge1NationalId = uuid() + const appealJudge1Name = uuid() const appealJudge2NationalId = uuid() + const appealJudge2Name = uuid() const appealJudge3NationalId = uuid() + const appealJudge3Name = uuid() const theCase = { id: caseId, @@ -36,10 +40,22 @@ describe('InternalCaseController - Deliver assigned roles to court of appeals', appealJudge1Id, appealJudge2Id, appealJudge3Id, - appealAssistant: { nationalId: appealAssistantNationalId }, - appealJudge1: { nationalId: appealJudge1NationalId }, - appealJudge2: { nationalId: appealJudge2NationalId }, - appealJudge3: { nationalId: appealJudge3NationalId }, + appealAssistant: { + nationalId: appealAssistantNationalId, + name: appealAssistantName, + }, + appealJudge1: { + nationalId: appealJudge1NationalId, + name: appealJudge1Name, + }, + appealJudge2: { + nationalId: appealJudge2NationalId, + name: appealJudge2Name, + }, + appealJudge3: { + nationalId: appealJudge3NationalId, + name: appealJudge3Name, + }, } as Case let mockCourtService: CourtService @@ -83,9 +99,13 @@ describe('InternalCaseController - Deliver assigned roles to court of appeals', caseId, appealCaseNumber, appealAssistantNationalId, + appealAssistantName, appealJudge1NationalId, + appealJudge1Name, appealJudge2NationalId, + appealJudge2Name, appealJudge3NationalId, + appealJudge3Name, ) expect(then.result).toEqual({ delivered: true }) }) diff --git a/apps/judicial-system/backend/src/app/modules/court/court.service.ts b/apps/judicial-system/backend/src/app/modules/court/court.service.ts index 63fa67d1d389..ba07206d0814 100644 --- a/apps/judicial-system/backend/src/app/modules/court/court.service.ts +++ b/apps/judicial-system/backend/src/app/modules/court/court.service.ts @@ -593,17 +593,25 @@ export class CourtService { caseId: string, appealCaseNumber?: string, appealAssistantNationalId?: string, + appealAssistantName?: string, appealJudge1NationalId?: string, + appealJudge1Name?: string, appealJudge2NationalId?: string, + appealJudge2Name?: string, appealJudge3NationalId?: string, + appealJudge3Name?: string, ): Promise { try { const subject = `Landsréttur - ${appealCaseNumber} - aðilar` const content = JSON.stringify({ appealAssistantNationalId, + appealAssistantName, appealJudge1NationalId, + appealJudge1Name, appealJudge2NationalId, + appealJudge2Name, appealJudge3NationalId, + appealJudge3Name, }) return this.sendToRobot( @@ -621,9 +629,13 @@ export class CourtService { institution: user.institution?.name, appealCaseNumber, appealAssistantNationalId, + appealAssistantName, appealJudge1NationalId, + appealJudge1Name, appealJudge2NationalId, + appealJudge2Name, appealJudge3NationalId, + appealJudge3Name, }, error, ) From 642e996891e30c3cf36eb2e8ea9f566df0f773ee Mon Sep 17 00:00:00 2001 From: Herdis Maria Date: Tue, 30 Apr 2024 11:44:15 +0000 Subject: [PATCH 4/7] fix(auth-api-lib): handle valid_to and valid_from null values in migration (#14640) * handle valid_to and valid_from null values in personal representative right type table in migration * add association decorators to models --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- ...pes-delegation-types-with-valid-to-null.js | 43 +++++++++++++++++++ .../models/delegation-provider.model.ts | 5 +++ .../models/delegation-type.model.ts | 7 ++- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 libs/auth-api-lib/migrations/20240429164830-migrate-api-scopes-delegation-types-with-valid-to-null.js diff --git a/libs/auth-api-lib/migrations/20240429164830-migrate-api-scopes-delegation-types-with-valid-to-null.js b/libs/auth-api-lib/migrations/20240429164830-migrate-api-scopes-delegation-types-with-valid-to-null.js new file mode 100644 index 000000000000..6c7e6defeacd --- /dev/null +++ b/libs/auth-api-lib/migrations/20240429164830-migrate-api-scopes-delegation-types-with-valid-to-null.js @@ -0,0 +1,43 @@ +'use strict' + +module.exports = { + async up(queryInterface) { + await queryInterface.sequelize.query(` + BEGIN; + + DELETE FROM api_scope_delegation_types; + + INSERT INTO api_scope_delegation_types (api_scope_name, delegation_type) + SELECT name, 'Custom' + FROM api_scope + WHERE allow_explicit_delegation_grant = true; + + INSERT INTO api_scope_delegation_types (api_scope_name, delegation_type) + SELECT name, 'LegalGuardian' + FROM api_scope + WHERE grant_to_legal_guardians = true; + + INSERT INTO api_scope_delegation_types (api_scope_name, delegation_type) + SELECT name, 'ProcurationHolder' + FROM api_scope + WHERE grant_to_procuring_holders = true; + + INSERT INTO api_scope_delegation_types (api_scope_name, delegation_type) + SELECT prsp.api_scope_name, CONCAT('PersonalRepresentative:', prrt.code) + FROM personal_representative_right_type prrt + JOIN personal_representative_scope_permission prsp ON prrt.code = prsp.right_type_code + JOIN api_scope apis ON prsp.api_scope_name = apis.name + WHERE (prrt.valid_from IS NULL OR prrt.valid_from < NOW()) AND (prrt.valid_to IS NULL OR prrt.valid_to > NOW()) AND apis.grant_to_personal_representatives = true; + + COMMIT; + `) + }, + + async down(queryInterface) { + await queryInterface.sequelize.query(` + BEGIN; + DELETE FROM api_scope_delegation_types; + COMMIT; + `) + }, +} diff --git a/libs/auth-api-lib/src/lib/delegations/models/delegation-provider.model.ts b/libs/auth-api-lib/src/lib/delegations/models/delegation-provider.model.ts index 9e947120b251..05352f3b6a6f 100644 --- a/libs/auth-api-lib/src/lib/delegations/models/delegation-provider.model.ts +++ b/libs/auth-api-lib/src/lib/delegations/models/delegation-provider.model.ts @@ -7,11 +7,13 @@ import { Column, CreatedAt, DataType, + HasMany, Model, PrimaryKey, Table, UpdatedAt, } from 'sequelize-typescript' +import { DelegationTypeModel } from './delegation-type.model' @Table({ tableName: 'delegation_provider', @@ -41,6 +43,9 @@ export class DelegationProviderModel extends Model< }) description!: string + @HasMany(() => DelegationTypeModel) + delegationTypes!: DelegationTypeModel[] + @CreatedAt readonly created!: CreationOptional diff --git a/libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts b/libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts index b980b8942f35..53e3ab85fbd2 100644 --- a/libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts +++ b/libs/auth-api-lib/src/lib/delegations/models/delegation-type.model.ts @@ -4,6 +4,7 @@ import type { InferCreationAttributes, } from 'sequelize' import { + BelongsTo, Column, CreatedAt, DataType, @@ -35,9 +36,13 @@ export class DelegationTypeModel extends Model< @Column({ type: DataType.STRING, allowNull: false, + field: 'provider', }) @ForeignKey(() => DelegationProviderModel) - provider!: string + providerId!: string + + @BelongsTo(() => DelegationProviderModel) + provider!: DelegationProviderModel @Column({ type: DataType.STRING, From a62ffa86c5b3a76d0a5725f421f91a1ff5ffce9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Tue, 30 Apr 2024 12:15:56 +0000 Subject: [PATCH 5/7] fix(j-s): Case Files to Robot (#14643) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../backend/src/app/modules/file/file.service.ts | 1 + .../app/modules/file/test/fileController/createCaseFile.spec.ts | 2 +- .../test/limitedAccessFileController/createCaseFile.spec.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/file/file.service.ts b/apps/judicial-system/backend/src/app/modules/file/file.service.ts index 89f131372162..80b8a0af5e6f 100644 --- a/apps/judicial-system/backend/src/app/modules/file/file.service.ts +++ b/apps/judicial-system/backend/src/app/modules/file/file.service.ts @@ -233,6 +233,7 @@ export class FileService { }) if ( + theCase.appealCaseNumber && file.category && [ CaseFileCategory.PROSECUTOR_APPEAL_STATEMENT, diff --git a/apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFile.spec.ts b/apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFile.spec.ts index f03f905ba416..6a53c85efd3e 100644 --- a/apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFile.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFile.spec.ts @@ -64,7 +64,7 @@ describe('FileController - Create case file', () => { 'case file created for %s case', (type) => { const caseId = uuid() - const theCase = { id: caseId, type } as Case + const theCase = { id: caseId, type, appealCaseNumber: uuid() } as Case const uuId = uuid() const createCaseFile: CreateFileDto = { type: 'text/plain', diff --git a/apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFile.spec.ts b/apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFile.spec.ts index 0be53642be0c..2866c817baee 100644 --- a/apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFile.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFile.spec.ts @@ -64,7 +64,7 @@ describe('limitedAccessFileController - Create case file', () => { 'case file created for %s case', (type) => { const caseId = uuid() - const theCase = { id: caseId, type } as Case + const theCase = { id: caseId, type, appealCaseNumber: uuid() } as Case const uuId = uuid() const createCaseFile: CreateFileDto = { type: 'text/plain', From 5cd0ad682435439f0f1d6ee40948b64c0893507a Mon Sep 17 00:00:00 2001 From: albinagu <47886428+albinagu@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:50:40 +0000 Subject: [PATCH 6/7] fix(web): paginated data in petition view (#14631) * fix(web): paginated data in petition view * Update apps/web/screens/PetitionView/PetitionView.tsx Co-authored-by: kksteini <77672665+kksteini@users.noreply.github.com> * chore: nx format:write update dirty files * revert --------- Co-authored-by: kksteini <77672665+kksteini@users.noreply.github.com> Co-authored-by: andes-it Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../screens/PetitionView/PetitionSkeleton.tsx | 4 +- .../web/screens/PetitionView/PetitionView.tsx | 134 +++++++++--------- apps/web/screens/PetitionView/pagination.ts | 19 --- apps/web/screens/PetitionView/queries.ts | 56 +++++--- apps/web/screens/PetitionView/utils.ts | 20 +++ 5 files changed, 125 insertions(+), 108 deletions(-) delete mode 100644 apps/web/screens/PetitionView/pagination.ts create mode 100644 apps/web/screens/PetitionView/utils.ts diff --git a/apps/web/screens/PetitionView/PetitionSkeleton.tsx b/apps/web/screens/PetitionView/PetitionSkeleton.tsx index 435d5b0e40c2..c843425f3f92 100644 --- a/apps/web/screens/PetitionView/PetitionSkeleton.tsx +++ b/apps/web/screens/PetitionView/PetitionSkeleton.tsx @@ -4,7 +4,7 @@ const Skeleton = () => { return ( - + @@ -13,7 +13,7 @@ const Skeleton = () => { - + ) } diff --git a/apps/web/screens/PetitionView/PetitionView.tsx b/apps/web/screens/PetitionView/PetitionView.tsx index bb6cf4020376..5db6054ae567 100644 --- a/apps/web/screens/PetitionView/PetitionView.tsx +++ b/apps/web/screens/PetitionView/PetitionView.tsx @@ -4,14 +4,13 @@ import { GridColumn, GridRow, Link, + SkeletonLoader, Stack, Text, } from '@island.is/island-ui/core' import { withMainLayout } from '@island.is/web/layouts/main' import { Box, Button, Table as T, Pagination } from '@island.is/island-ui/core' -import { PAGE_SIZE, pages, paginate } from './pagination' import { Screen } from '../../types' -import format from 'date-fns/format' import { useRouter } from 'next/router' import { useGetPetitionList, useGetPetitionListEndorsements } from './queries' import { LinkType, linkResolver, useNamespace } from '@island.is/web/hooks' @@ -25,19 +24,12 @@ import { import { GET_NAMESPACE_QUERY } from '@island.is/web/screens/queries' import { useI18n } from '@island.is/web/i18n' import PetitionSkeleton from './PetitionSkeleton' +import { formatDate, getBaseUrl, pageSize } from './utils' interface PetitionViewProps { namespace?: Record } -const formatDate = (date: string) => { - try { - return format(new Date(date), 'dd.MM.yyyy') - } catch { - return date - } -} - const PetitionView: Screen = ({ namespace }) => { const n = useNamespace(namespace) const router = useRouter() @@ -47,33 +39,23 @@ const PetitionView: Screen = ({ namespace }) => { router.query.slug as string, ) - const { listEndorsements, loadingEndorsements } = - useGetPetitionListEndorsements(router.query.slug as string) - - const [page, setPage] = useState(1) - const [totalPages, setTotalPages] = useState(0) - const [pagePetitions, setPetitions] = useState(listEndorsements.data ?? []) + const [cursor, setCursor] = useState('') + const [pageDirection, setPageDirection] = useState<'before' | 'after' | ''>( + '', + ) - const getBaseUrl = () => { - const baseUrl = - window.location.origin === 'http://localhost:4200' - ? 'http://localhost:4242' - : window.location.origin + const { listEndorsements, loadingEndorsements, refetch } = + useGetPetitionListEndorsements( + router.query.slug as string, + cursor, + pageDirection, + ) - return `${baseUrl}/umsoknir/undirskriftalisti` - } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore make web strict - const handlePagination = (page, petitions) => { - setPage(page) - setTotalPages(pages(petitions?.length)) - setPetitions(paginate(petitions, PAGE_SIZE, page)) - } + const [page, setPage] = useState(1) useEffect(() => { - setPetitions(listEndorsements.data ?? []) - handlePagination(1, listEndorsements.data ?? []) - }, [listEndorsements.data]) + refetch() + }, [cursor, pageDirection]) return ( @@ -166,9 +148,9 @@ const PetitionView: Screen = ({ namespace }) => { {n('listOpenFromTil', 'Gildistímabil lista:')} - {formatDate(list.openedDate) + + {formatDate(String(list.openedDate)) + ' - ' + - formatDate(list.closedDate)} + formatDate(String(list.closedDate))} @@ -181,11 +163,7 @@ const PetitionView: Screen = ({ namespace }) => { {n('signedPetitions', 'Fjöldi undirskrifta:')} - - {loadingEndorsements - ? n('loadingEndorsements', 'Sæki gögn...') - : listEndorsements.totalCount} - + {listEndorsements.totalCount} @@ -208,39 +186,67 @@ const PetitionView: Screen = ({ namespace }) => { - { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore make web strict - pagePetitions?.map((petition) => { - return ( - - - {formatDate(petition.created)} - - - {petition.meta.fullName - ? petition.meta.fullName - : n('noName', 'Nafn ekki skráð')} - - - ) - }) - } + {loadingEndorsements && + Array.from({ length: 10 }, (_, i) => ( + + + + + + + + + ))} + {!loadingEndorsements && + listEndorsements.data + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore make web strict + ?.map((petition) => { + return ( + + + {formatDate(petition.created)} + + + {petition.meta.fullName + ? petition.meta.fullName + : n('noName', 'Nafn ekki skráð')} + + + ) + })} {list.closedDate && new Date() <= new Date(list.closedDate) ? ( - pagePetitions && pagePetitions.length ? ( + listEndorsements.data && listEndorsements.data.length ? ( ( + totalItems={listEndorsements.totalCount} + itemsPerPage={pageSize} + renderLink={(p, className, children) => ( - handlePagination(page, listEndorsements.data) - } + component="button" + onClick={() => { + setPage(p) + if ( + p > page && + listEndorsements.pageInfo.hasNextPage + ) { + setPageDirection('after') + setCursor(listEndorsements.pageInfo.endCursor ?? '') + } else if ( + p < page && + listEndorsements.pageInfo.hasPreviousPage + ) { + setPageDirection('before') + setCursor( + listEndorsements.pageInfo.startCursor ?? '', + ) + } + }} > {children} diff --git a/apps/web/screens/PetitionView/pagination.ts b/apps/web/screens/PetitionView/pagination.ts deleted file mode 100644 index 52925d83e5d1..000000000000 --- a/apps/web/screens/PetitionView/pagination.ts +++ /dev/null @@ -1,19 +0,0 @@ -export const PAGE_SIZE = 10 - -export function paginate( - petitions: string[], - pageSize: number, - pageNumber: number, -) { - if (petitions === undefined) return - else { - return petitions.slice((pageNumber - 1) * pageSize, pageNumber * pageSize) - } -} - -export function pages(petitionsLength: number) { - if (petitionsLength === undefined) return 0 - else { - return Math.ceil(petitionsLength / PAGE_SIZE) - } -} diff --git a/apps/web/screens/PetitionView/queries.ts b/apps/web/screens/PetitionView/queries.ts index 8280452df2d2..a94d3d383dbf 100644 --- a/apps/web/screens/PetitionView/queries.ts +++ b/apps/web/screens/PetitionView/queries.ts @@ -1,13 +1,9 @@ import gql from 'graphql-tag' import { useQuery } from '@apollo/client' - -interface PetitionListResponse { - endorsementSystemGetGeneralPetitionList: any -} - -interface PetitionListEndorsementsResponse { - endorsementSystemGetGeneralPetitionEndorsements: any -} +import { + EndorsementList, + PaginatedEndorsementResponse, +} from '@island.is/web/graphql/schema' const GetGeneralPetitionList = gql` query endorsementSystemGetGeneralPetitionList( @@ -33,6 +29,12 @@ const GetGeneralPetitionListEndorsements = gql` ) { endorsementSystemGetGeneralPetitionEndorsements(input: $input) { totalCount + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } data { id endorser @@ -51,7 +53,7 @@ export const useGetPetitionList = (listId: string) => { data: endorsementListsResponse, loading, error, - } = useQuery(GetGeneralPetitionList, { + } = useQuery(GetGeneralPetitionList, { variables: { input: { listId: listId, @@ -60,28 +62,36 @@ export const useGetPetitionList = (listId: string) => { }) const list = - endorsementListsResponse?.endorsementSystemGetGeneralPetitionList ?? [] + (endorsementListsResponse?.endorsementSystemGetGeneralPetitionList as EndorsementList) ?? + [] return { list, loading, error } } -export const useGetPetitionListEndorsements = (listId: string) => { - const { data: endorsementListsResponse, loading: loadingEndorsements } = - useQuery( - GetGeneralPetitionListEndorsements, - { - variables: { - input: { - listId: listId, - limit: 1000, - }, - }, +export const useGetPetitionListEndorsements = ( + listId: string, + cursor?: string, + pageDirection?: 'before' | 'after' | '', +) => { + const { + data: endorsementListsResponse, + loading: loadingEndorsements, + refetch, + } = useQuery(GetGeneralPetitionListEndorsements, { + variables: { + input: { + before: pageDirection === 'before' ? cursor : '', + after: pageDirection === 'after' ? cursor : '', + listId: listId, + limit: 10, }, - ) + }, + }) return { listEndorsements: - endorsementListsResponse?.endorsementSystemGetGeneralPetitionEndorsements ?? + (endorsementListsResponse?.endorsementSystemGetGeneralPetitionEndorsements as PaginatedEndorsementResponse) ?? [], loadingEndorsements, + refetch, } } diff --git a/apps/web/screens/PetitionView/utils.ts b/apps/web/screens/PetitionView/utils.ts new file mode 100644 index 000000000000..874da3937e33 --- /dev/null +++ b/apps/web/screens/PetitionView/utils.ts @@ -0,0 +1,20 @@ +import format from 'date-fns/format' + +export const formatDate = (date: string) => { + try { + return format(new Date(date), 'dd.MM.yyyy') + } catch { + return date + } +} + +export const getBaseUrl = () => { + const baseUrl = + window.location.origin === 'http://localhost:4200' + ? 'http://localhost:4242' + : window.location.origin + + return `${baseUrl}/umsoknir/undirskriftalisti` +} + +export const pageSize = 10 From 57a4c0533db0e150613f130abc014dca59700eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3n=20Ingi?= <42949613+joningi98@users.noreply.github.com> Date: Tue, 30 Apr 2024 13:01:55 +0000 Subject: [PATCH 7/7] fix(general-petition): Fix form validation (#14589) * Fixing form validation * update validation * update isValidPhoneNumber & isValidEmail --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../general-petition/src/lib/dataSchema.ts | 15 ++++++++++----- .../general-petition/src/lib/messages.ts | 13 ++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libs/application/templates/general-petition/src/lib/dataSchema.ts b/libs/application/templates/general-petition/src/lib/dataSchema.ts index b6b221ce9b41..f285592ba215 100644 --- a/libs/application/templates/general-petition/src/lib/dataSchema.ts +++ b/libs/application/templates/general-petition/src/lib/dataSchema.ts @@ -9,12 +9,13 @@ const FileSchema = z.object({ const isValidPhoneNumber = (phoneNumber: string) => { const phone = parsePhoneNumberFromString(phoneNumber, 'IS') - return phone && phone.isValid() + return phone && phone.isValid() && phoneNumber.length > 0 } const emailRegex = /^[\w!#$%&'*+/=?`{|}~^-]+(?:\.[\w!#$%&'*+/=?`{|}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$/i -export const isValidEmail = (value: string) => emailRegex.test(value) +export const isValidEmail = (value: string): boolean => + emailRegex.test(value) && value.length > 0 export const GeneralPetitionSchema = z.object({ approveTermsAndConditions: z @@ -50,14 +51,18 @@ export const GeneralPetitionSchema = z.object({ }) .refine( ({ dateFrom, dateTil }) => - !dateFrom || !dateTil || new Date(dateFrom) <= new Date(dateTil), + !dateFrom || !dateTil || new Date(dateFrom) < new Date(dateTil), { message: m.validationTilBeforeFrom.defaultMessage as string, path: ['dateTil'], }, ), - phone: z.string().refine((v) => isValidPhoneNumber(v)), - email: z.string().refine((v) => isValidEmail(v)), + phone: z.string().refine((v) => isValidPhoneNumber(v), { + message: m.validationPhone.defaultMessage as string, + }), + email: z.string().refine((v) => isValidEmail(v), { + message: m.validationEmail.defaultMessage as string, + }), }) export type File = z.TypeOf diff --git a/libs/application/templates/general-petition/src/lib/messages.ts b/libs/application/templates/general-petition/src/lib/messages.ts index 975dd6f63830..687c41473b11 100644 --- a/libs/application/templates/general-petition/src/lib/messages.ts +++ b/libs/application/templates/general-petition/src/lib/messages.ts @@ -242,7 +242,18 @@ export const m = defineMessages({ }, validationTilBeforeFrom: { id: 'gpl.application:validationTilBeforeFrom', - defaultMessage: 'Lokadagsetning má ekki vera á undan upphafsdagsetningu', + defaultMessage: + 'Lokadagsetning má ekki vera á undan eða sú sama og upphafsdagsetning', + description: '', + }, + validationPhone: { + id: 'gpl.application:validationPhone', + defaultMessage: 'Vinsamlegast sláðu inn gilt símanúmer', + description: '', + }, + validationEmail: { + id: 'gpl.application:validationEmail', + defaultMessage: 'Vinsamlegast sláðu inn gilt netfang', description: '', },