Skip to content

Commit

Permalink
add collectors to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
juni-haukur committed Sep 25, 2024
1 parent 38590bc commit 318bb3e
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ export class SignatureCollectionResolver {
@Audit()
async signatureCollectionCollectors(
@CurrentUser() user: User,
@Args('input') input: SignatureCollectionCandidateIdInput,
@CurrentSignee() signee: SignatureCollectionSignee,
): Promise<SignatureCollectionCollector[]> {
return this.signatureCollectionService.collectors(user, input)
return this.signatureCollectionService.collectors(
user,
signee.candidate?.id,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,14 @@ export class SignatureCollectionService {

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

async getCollectors(
auth: User,
{ candidateId }: { candidateId: string },
candidateId: string,
): Promise<{ name: string; nationalId: string }[]> {
const candidate = await this.getApiWithAuth(
this.candidateApi,
Expand Down
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 @@ -180,8 +184,18 @@ const OwnerView = ({
</T.Head>
<T.Body>
<T.Row>
<T.Data width={'40%'}>{'Nafni Nafnason'}</T.Data>
<T.Data>{'010130-3019'}</T.Data>
{loadingCollectors ? (
<T.Data colSpan={2}>
<CollectorSkeleton></CollectorSkeleton>
</T.Data>
) : (
collectors.map((collector) => (
<>
<T.Data width={'40%'}>{collector.name}</T.Data>
<T.Data>{collector.nationalId}</T.Data>
</>
))
)}
</T.Row>
</T.Body>
</T.Table>
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} />
)
}

0 comments on commit 318bb3e

Please sign in to comment.