Skip to content

Commit

Permalink
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
Browse files Browse the repository at this point in the history
  • Loading branch information
magnearun authored Oct 3, 2024
2 parents 8cee9be + 7a9c112 commit e91f452
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 87 deletions.
139 changes: 79 additions & 60 deletions apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GridColumn,
GridContainer,
GridRow,
LoadingDots,
Stack,
Text,
} from '@island.is/island-ui/core'
Expand Down Expand Up @@ -33,7 +34,9 @@ interface BoxProps {
vinNumber?: string
outInStatus: number
useStatus: string
reloadFlag: boolean // To force reload of the component to make sure the data in the parent is correct
plateCount: number
onPlateCountChange: (value: number) => void
isLoading: boolean
}

export const CarDetailsBox2: FC<React.PropsWithChildren<BoxProps>> = ({
Expand All @@ -45,6 +48,9 @@ export const CarDetailsBox2: FC<React.PropsWithChildren<BoxProps>> = ({
mileage,
outInStatus,
useStatus,
onPlateCountChange,
plateCount,
isLoading,
}) => {
const {
t: {
Expand Down Expand Up @@ -114,67 +120,80 @@ export const CarDetailsBox2: FC<React.PropsWithChildren<BoxProps>> = ({
</GridRow>
)}

{(outInStatus === OutInUsage.IN ||
(outInStatus === OutInUsage.OUT &&
useStatus === UseStatus.OUT_TICKET)) && (
<GridRow>
<GridColumn span="12/12">
<SelectController
label={t.numberplate.count}
id="plateCount"
name="plateCount"
options={[
{ label: '0', value: 0 },
{ label: '1', value: 1 },
{ label: '2', value: 2 },
]}
onSelect={(option) => {
if (option?.value === 2) {
setMissingPlates(false)
setLostPlate(false)
} else {
setMissingPlates(true)
}
}}
defaultValue={2}
/>
</GridColumn>
</GridRow>
)}
{missingPlates && (
<GridRow>
<GridColumn span="12/12">
<Controller
name="plateLost"
render={({ field: { onChange, value, name } }) => {
return (
<Checkbox
large
name={name}
label={t.numberplate.lost}
onChange={() => {
if (!lostPlate) {
onChange(PlateInfo.PLATE_LOST)
} else {
onChange()
}
{isLoading ? (
<Box textAlign="center">
<LoadingDots />
</Box>
) : (
<Box>
{(outInStatus === OutInUsage.IN ||
(outInStatus === OutInUsage.OUT &&
useStatus === UseStatus.OUT_TICKET)) && (
<GridRow>
<GridColumn span="12/12">
<SelectController
label={t.numberplate.count}
id="plateCount"
name="plateCount"
options={[
{ label: '0', value: 0 },
{ label: '1', value: 1 },
{ label: '2', value: 2 },
]}
onSelect={(option) => {
onPlateCountChange(option?.value)

setLostPlate(!lostPlate)
}}
/>
)
}}
/>
</GridColumn>
</GridRow>
)}
if (option?.value === 2) {
setMissingPlates(false)
setLostPlate(false)
} else {
setMissingPlates(true)
}
}}
defaultValue={plateCount}
/>
</GridColumn>
</GridRow>
)}
{missingPlates && (
<GridRow>
<GridColumn span="12/12">
<Controller
name="plateLost"
render={({ field: { onChange, value, name } }) => {
return (
<Checkbox
large
name={name}
label={t.numberplate.lost}
onChange={() => {
if (!lostPlate) {
onChange(PlateInfo.PLATE_LOST)
} else {
onChange()
}

{lostPlate && (
<GridRow>
<GridColumn span="12/12">
<AlertMessage type="info" message={t.numberplate.missingInfo} />
</GridColumn>
</GridRow>
setLostPlate(!lostPlate)
}}
/>
)
}}
/>
</GridColumn>
</GridRow>
)}

{lostPlate && (
<GridRow>
<GridColumn span="12/12">
<AlertMessage
type="info"
message={t.numberplate.missingInfo}
/>
</GridColumn>
</GridRow>
)}
</Box>
)}
</Stack>
</GridContainer>
Expand Down
53 changes: 29 additions & 24 deletions apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,17 @@ const UpdateSkilavottordVehicleInfoMutation = gql`
`

const Confirm: FC<React.PropsWithChildren<unknown>> = () => {
const [reloadFlag, setReloadFlag] = useState(false)
const [plateCount, setPlateCount] = useState<number>(2)

const handlePlateCountChange = (value: number) => {
setPlateCount(value)
}

const [
vehicleReadyToDeregisteredQueryCompleted,
setVehicleReadyToDeregisteredQueryCompleted,
] = useState(false)

// Update reloadFlag to trigger the child component to reload
const triggerReload = () => {
setReloadFlag(true)
}

useEffect(() => {
triggerReload()
}, [setReloadFlag])

const methods = useForm({
mode: 'onChange',
})
Expand All @@ -132,20 +128,20 @@ const Confirm: FC<React.PropsWithChildren<unknown>> = () => {

const mileageValue = watch('mileage')
const plateLost = watch('plateLost')
const plateCountValue = watch('plateCount')

const { data, loading } = useQuery<Query>(
SkilavottordVehicleReadyToDeregisteredQuery,
{
variables: { permno: id },
onCompleted: (data) => {
if (data && data.skilavottordVehicleReadyToDeregistered) {
setVehicleReadyToDeregisteredQueryCompleted(true)
}
},
},
)

useEffect(() => {
if (data && data.skilavottordVehicleReadyToDeregistered) {
setVehicleReadyToDeregisteredQueryCompleted(true)
}
}, [data])

const vehicle = data?.skilavottordVehicleReadyToDeregistered

const { data: traffic, loading: loadingTraffic } = useQuery<Query>(
Expand All @@ -165,6 +161,17 @@ const Confirm: FC<React.PropsWithChildren<unknown>> = () => {

const useStatus = vehicleTrafficData?.useStatus || '01'

useEffect(() => {
if (vehicleTrafficData) {
if (
outInStatus === OutInUsage.OUT &&
useStatus !== UseStatus.OUT_TICKET
) {
setPlateCount(0)
}
}
}, [vehicleTrafficData])

const [
setRecyclingRequest,
{ data: mutationData, error: mutationError, loading: mutationLoading },
Expand Down Expand Up @@ -205,19 +212,13 @@ const Confirm: FC<React.PropsWithChildren<unknown>> = () => {

const handleConfirm = () => {
let newMileage = mileageValue
let plateCount = plateCountValue

if (mileageValue !== undefined) {
newMileage = +mileageValue.trim().replace(/\./g, '')
} else {
newMileage = vehicle?.mileage
}

// If vehicle is out of use and not using ticket, set plate count to 0
if (outInStatus === OutInUsage.OUT && useStatus !== UseStatus.OUT_TICKET) {
plateCount = 0
}

// Update vehicle table with latests information
setVehicleRequest({
variables: {
Expand Down Expand Up @@ -301,7 +302,9 @@ const Confirm: FC<React.PropsWithChildren<unknown>> = () => {
mileage={vehicle.mileage || 0}
outInStatus={outInStatus}
useStatus={useStatus || ''}
reloadFlag={reloadFlag}
plateCount={plateCount}
onPlateCountChange={handlePlateCountChange}
isLoading={loadingTraffic}
/>
</FormProvider>
</Stack>
Expand Down Expand Up @@ -344,7 +347,9 @@ const Confirm: FC<React.PropsWithChildren<unknown>> = () => {
</Button>
</Hidden>
{vehicle && (
<Button onClick={handleConfirm}>{t.buttons.confirm}</Button>
<Button onClick={handleConfirm} disabled={loadingTraffic}>
{t.buttons.confirm}
</Button>
)}
</Box>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IsString } from 'class-validator'
import { Field, InputType } from '@nestjs/graphql'

@InputType()
export class SignatureCollectionSignatureLookupInput {
@Field()
@IsString()
collectionId!: string
@Field()
@IsString()
nationalId!: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ import { SignatureCollectionSignatureIdInput } from './dto/signatureId.input'
import { SignatureCollectionIdInput } from './dto/collectionId.input'
import { SignatureCollectionCandidateIdInput } from './dto/candidateId.input'
import { SignatureCollectionCanSignFromPaperInput } from './dto/canSignFromPaper.input'
import { ReasonKey } from '@island.is/clients/signature-collection'
import { CanSignInfo } from './models/canSignInfo.model'
import { SignatureCollectionSignatureUpdateInput } from './dto/signatureUpdate.input'
import { SignatureCollectionAreaInput } from './dto'
import { SignatureCollectionSignatureLookupInput } from './dto/signatureLookup.input'
import { SignatureCollectionAreaSummaryReportInput } from './dto/areaSummaryReport.input'
import { SignatureCollectionAreaSummaryReport } from './models/areaSummaryReport.model'

Expand Down Expand Up @@ -267,6 +266,19 @@ export class SignatureCollectionAdminResolver {
)
}

@Query(() => [SignatureCollectionSignature])
@Scopes(
AdminPortalScope.signatureCollectionManage,
AdminPortalScope.signatureCollectionProcess,
)
@Audit()
async signatureCollectionSignatureLookup(
@CurrentUser() user: User,
@Args('input') input: SignatureCollectionSignatureLookupInput,
): Promise<SignatureCollectionSignature[]> {
return this.signatureCollectionService.signatureLookup(user, input)
}

@Query(() => SignatureCollectionAreaSummaryReport)
@Audit()
async signatureCollectionAreaSummaryReport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { SignatureCollectionSlug } from './models/slug.model'
import { SignatureCollectionListStatus } from './models/status.model'
import { SignatureCollectionIdInput } from './dto/collectionId.input'
import { SignatureCollectionSignatureUpdateInput } from './dto/signatureUpdate.input'
import { SignatureCollectionAreaInput } from './dto'
import { SignatureCollectionSignatureLookupInput } from './dto/signatureLookup.input'
import { SignatureCollectionAreaSummaryReportInput } from './dto/areaSummaryReport.input'
import { SignatureCollectionAreaSummaryReport } from './models/areaSummaryReport.model'

Expand Down Expand Up @@ -199,6 +199,17 @@ export class SignatureCollectionAdminService {
)
}

async signatureLookup(
user: User,
input: SignatureCollectionSignatureLookupInput,
): Promise<SignatureCollectionSignature[]> {
return await this.signatureCollectionClientService.signatureLookup(
user,
input.collectionId,
input.nationalId,
)
}

async getAreaSummaryReport(
input: SignatureCollectionAreaSummaryReportInput,
user: User,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,27 @@ export class SignatureCollectionAdminClientService {
return {} as AreaSummaryReport
}
}

async signatureLookup(
auth: Auth,
collectionId: string,
nationalId: string,
): Promise<Signature[]> {
const lists = await this.getLists({ collectionId }, auth)
try {
const res = await this.getApiWithAuth(
this.adminApi,
auth,
).adminMedmaelasofnunIDComparePost({
iD: parseInt(collectionId, 10),
requestBody: [nationalId],
})
return res.map(mapSignature).map((s) => ({
...s,
listTitle: lists.find((l) => l.id === s.listId)?.title,
}))
} catch {
return []
}
}
}

0 comments on commit e91f452

Please sign in to comment.