Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(signature-collection): Get candidate collectors #16146

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { SignatureCollectionCanSignFromPaperInput } from './dto/canSignFromPaper
import { SignatureCollectionAddListsInput } from './dto/addLists.input'
import { SignatureCollectionListBulkUploadInput } from './dto/bulkUpload.input'
import { SignatureCollectionUploadPaperSignatureInput } from './dto/uploadPaperSignature.input'
import { SignatureCollectionCollector } from './models/collector.model'
import { SignatureCollectionCandidateIdInput } from './dto/candidateId.input'
@UseGuards(IdsUserGuard, ScopesGuard, UserAccessGuard)
@Resolver()
@Audit({ namespace: '@island.is/api/signature-collection' })
Expand Down Expand Up @@ -186,4 +188,18 @@ export class SignatureCollectionResolver {
user,
)
}

@Scopes(ApiScope.signatureCollection)
@AccessRequirement(OwnerAccess.AllowActor)
@Query(() => [SignatureCollectionCollector])
@Audit()
async signatureCollectionCollectors(
@CurrentUser() user: User,
@CurrentSignee() signee: SignatureCollectionSignee,
): Promise<SignatureCollectionCollector[]> {
return this.signatureCollectionService.collectors(
user,
signee.candidate?.id,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { SignatureCollectionOwnerInput } from './dto/owner.input'
import { SignatureCollectionListBulkUploadInput } from './dto/bulkUpload.input'
import { SignatureCollectionUploadPaperSignatureInput } from './dto/uploadPaperSignature.input'
import { SignatureCollectionCanSignFromPaperInput } from './dto/canSignFromPaper.input'
import { SignatureCollectionCandidateIdInput } from './dto/candidateId.input'
import { SignatureCollectionCollector } from './models/collector.model'

@Injectable()
export class SignatureCollectionService {
Expand Down Expand Up @@ -161,4 +163,17 @@ export class SignatureCollectionService {

return canSign && list.area.id === signee.area?.id
}

async collectors(
user: User,
candidateId: string | undefined,
): Promise<SignatureCollectionCollector[]> {
if (!candidateId) {
return []
}
return await this.signatureCollectionClientService.getCollectors(
user,
candidateId,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,23 @@ export class SignatureCollectionClientService {
}
return { success: true }
}

async getCollectors(
auth: User,
candidateId: string,
): Promise<{ name: string; nationalId: string }[]> {
const candidate = await this.getApiWithAuth(
this.candidateApi,
auth,
).frambodIDGet({
iD: parseInt(candidateId),
})

return (
candidate.umbodList?.map((u) => ({
name: u.nafn ?? '',
nationalId: u.kennitala ?? '',
})) ?? []
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,12 @@ export const GetCanSign = gql`
signatureCollectionCanSignFromPaper(input: $input)
}
`

export const GetCollectors = gql`
query SignatureCollectionCollectors {
signatureCollectionCollectors {
nationalId
name
}
}
`
11 changes: 11 additions & 0 deletions libs/service-portal/signature-collection/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
GetListsForOwner,
GetCurrentCollection,
GetCanSign,
GetCollectors,
} from './graphql/queries'
import {
SignatureCollectionListBase,
Expand All @@ -16,6 +17,7 @@ import {
SignatureCollectionSuccess,
SignatureCollection,
SignatureCollectionSignedList,
SignatureCollectionCollector,
} from '@island.is/api/schema'

export const useGetSignatureList = (listId: string) => {
Expand Down Expand Up @@ -169,3 +171,12 @@ export const useGetCanSign = (
const canSign = getCanSignData?.signatureCollectionCanSignFromPaper ?? false
return { canSign, loadingCanSign }
}

export const useGetCollectors = () => {
const { data: getCollectorsData, loading: loadingCollectors } =
useQuery(GetCollectors)
const collectors =
(getCollectorsData?.signatureCollectionCollectors as SignatureCollectionCollector[]) ??
[]
return { collectors, loadingCollectors }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import {
SignatureCollectionList,
SignatureCollectionSuccess,
} from '@island.is/api/schema'
import { OwnerParliamentarySkeleton } from '../../../skeletons'
import { useGetListsForOwner } from '../../../hooks'
import {
CollectorSkeleton,
OwnerParliamentarySkeleton,
} from '../../../skeletons'
import { useGetCollectors, useGetListsForOwner } from '../../../hooks'
import { SignatureCollection } from '@island.is/api/schema'
import { useMutation } from '@apollo/client'
import { cancelCollectionMutation } from '../../../hooks/graphql/mutations'
Expand All @@ -36,6 +39,7 @@ const OwnerView = ({
const { formatMessage } = useLocale()
const { listsForOwner, loadingOwnerLists, refetchListsForOwner } =
useGetListsForOwner(currentCollection?.id || '')
const { collectors, loadingCollectors } = useGetCollectors()

const [cancelCollection] = useMutation<SignatureCollectionSuccess>(
cancelCollectionMutation,
Expand Down Expand Up @@ -179,10 +183,20 @@ const OwnerView = ({
</T.Row>
</T.Head>
<T.Body>
<T.Row>
<T.Data width={'40%'}>{'Nafni Nafnason'}</T.Data>
<T.Data>{'010130-3019'}</T.Data>
</T.Row>
{loadingCollectors ? (
<T.Row>
<T.Data colSpan={2}>
<CollectorSkeleton></CollectorSkeleton>
</T.Data>
</T.Row>
) : (
collectors.map((collector) => (
<T.Row key={collector.nationalId}>
<T.Data width={'40%'}>{collector.name}</T.Data>
<T.Data>{collector.nationalId}</T.Data>
</T.Row>
))
)}
</T.Body>
</T.Table>
</Box>
Expand Down
6 changes: 6 additions & 0 deletions libs/service-portal/signature-collection/src/skeletons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ export const SkeletonTable = () => {
</Box>
)
}

export const CollectorSkeleton = () => {
return (
<SkeletonLoader height={50} borderRadius="large" repeat={2} space={1} />
)
}
Loading