Skip to content

Commit

Permalink
Fix: PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
justiandevs committed Nov 6, 2024
1 parent d9924d1 commit 9216c1b
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 52 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"primaryColor": "#24578f"
},
"map": {
"find_address_in_distance": 30,
"center": [
52.3731081,
4.8932945
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Paragraph } from '@/components/index'
import { RenderSingleField } from '@/app/[locale]/incident/add/components/questions/RenderSingleField'
import { LocationSelect } from '@/app/[locale]/incident/add/components/questions/LocationSelect'
import { useTranslations } from 'next-intl'
import { isCoordinates } from '@/lib/utils/map'

export const IncidentQuestionsLocationForm = () => {
const { formState: formStoreState, updateForm } = useFormStore()
Expand All @@ -36,12 +37,6 @@ export const IncidentQuestionsLocationForm = () => {
formStoreState.sub_category
)

console.log(
additionalQuestions,
formStoreState.main_category,
formStoreState.sub_category
)

setAdditionalQuestions(additionalQuestions)

setLoading(false)
Expand All @@ -56,7 +51,7 @@ export const IncidentQuestionsLocationForm = () => {

useEffect(() => {
if (
formStoreState.coordinates &&
isCoordinates(formStoreState.coordinates) &&
formStoreState.coordinates[0] === 0 &&
formStoreState.coordinates[1] === 0
) {
Expand Down
15 changes: 8 additions & 7 deletions src/app/[locale]/incident/add/components/MapDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Map, {
import { useTranslations } from 'next-intl'
import * as VisuallyHidden from '@radix-ui/react-visually-hidden'
import { useFormStore } from '@/store/form_store'
import { Heading } from '@/components/index'
import { Heading, Icon } from '@/components/index'
import { useConfig } from '@/hooks/useConfig'
import { Button } from '@/components/index'
import { IconMapPinFilled } from '@tabler/icons-react'
Expand Down Expand Up @@ -110,18 +110,19 @@ const MapDialog = ({ trigger }: MapDialogProps) => {
id="dialogMap"
onClick={(e) => handleMapClick(e)}
onMove={(evt) => setViewState(evt.viewState)}
style={{ width: '100%', height: '100%' }}
style={{ blockSize: '100%', inlineSize: '100%' }}
mapStyle={`${process.env.NEXT_PUBLIC_MAPTILER_MAP}/style.json?key=${process.env.NEXT_PUBLIC_MAPTILER_API_KEY}`}
attributionControl={false}
maxBounds={config.base.map.maxBounds}
>
{marker.length && (
<Marker latitude={marker[0]} longitude={marker[1]}>
<IconMapPinFilled
size={42}
className="-translate-y-1/2"
color={config.base.style.primaryColor}
/>
<Icon className="map-marker-icon">
<IconMapPinFilled
className="-translate-y-1/2"
color={config.base.style.primaryColor}
/>
</Icon>
</Marker>
)}
</Map>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import React, { useEffect, useState } from 'react'
import { Button, Paragraph } from '@/components/index'
import { useFormStore } from '@/store/form_store'
import { getNearestAddressByCoordinate } from '@/services/location/address'
import { useConfig } from '@/hooks/useConfig'
import { isCoordinates } from '@/lib/utils/map'
import { Alert } from '@utrecht/component-library-react/dist/css-module'
import { LinkButton } from '@utrecht/component-library-react'

export interface LocationSelectProps {
field?: PublicQuestion
Expand All @@ -19,13 +23,14 @@ export const LocationSelect = ({ field }: LocationSelectProps) => {
const errorMessage = errors['location']?.message as string
const { formState: formStoreState } = useFormStore()
const [address, setAddress] = useState<string | null>(null)
const { config } = useConfig()

useEffect(() => {
const getAddress = async () => {
const result = await getNearestAddressByCoordinate(
formStoreState.coordinates[0],
formStoreState.coordinates[1],
10
config ? config.base.map.find_address_in_distance : 30
)

if (result) {
Expand All @@ -39,41 +44,36 @@ export const LocationSelect = ({ field }: LocationSelectProps) => {
}, [formStoreState.coordinates])

return (
<div className="relative w-full">
{errorMessage && (
<Paragraph
id="location-error"
aria-live="assertive"
style={{ color: 'red' }}
>
{errorMessage}
</Paragraph>
)}
<div className="w-full">
{errorMessage && <Alert type="error">{errorMessage}</Alert>}
<label htmlFor="location-button">
{field ? field.meta.label : 'Waar is het?'}
</label>
<LocationMap />
<Paragraph>{address}</Paragraph>
<MapProvider>
<MapDialog
trigger={
formStoreState.coordinates[0] === 0 &&
formStoreState.coordinates[1] === 0 ? (
<Button
id="location-button"
className="absolute top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2 border-none"
type="button"
>
Kies locatie
</Button>
) : (
<button id="location-button" type="button">
Wijzig locatie
</button>
)
}
/>
</MapProvider>
<div className="relative w-full">
<LocationMap />
<Paragraph>{address}</Paragraph>
<MapProvider>
<MapDialog
trigger={
isCoordinates(formStoreState.coordinates) &&
formStoreState.coordinates[0] === 0 &&
formStoreState.coordinates[1] === 0 ? (
<Button
id="location-button"
className="absolute top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2 border-none"
type="button"
>
Kies locatie
</Button>
) : (
<LinkButton inline={true} id="location-button" type="button">
Wijzig locatie
</LinkButton>
)
}
/>
</MapProvider>
</div>
{/* TODO: toon locatie, straatnaam bijv. */}
</div>
)
Expand Down
5 changes: 5 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@
left: 29px;
border-radius: 50%;
border: 1px solid rgb(0, 32, 92);
}

/* map */
.map-marker-icon {
--utrecht-icon-size: 42px;
}
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export {
Link,
Paragraph,
PreHeading,
Icon,
} from '@utrecht/component-library-react/dist/css-module'
12 changes: 7 additions & 5 deletions src/components/ui/LocationMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useEffect, useMemo, useState } from 'react'
import { useFormStore } from '@/store/form_store'
import { useConfig } from '@/hooks/useConfig'
import { IconMapPinFilled } from '@tabler/icons-react'
import { Icon } from '@/components/index'

const LocationMap = () => {
const { formState } = useFormStore()
Expand Down Expand Up @@ -69,11 +70,12 @@ const LocationMap = () => {
attributionControl={false}
>
<Marker latitude={marker[0]} longitude={marker[1]}>
<IconMapPinFilled
size={42}
className="-translate-y-1/2"
color={config.base.style.primaryColor}
/>
<Icon className="map-marker-icon">
<IconMapPinFilled
className="-translate-y-1/2"
color={config.base.style.primaryColor}
/>
</Icon>
</Marker>
</Map>
)
Expand Down
8 changes: 8 additions & 0 deletions src/lib/utils/map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const isCoordinates = (arg: unknown): arg is [number, number] => {
return (
Array.isArray(arg) &&
arg.length === 2 &&
typeof arg[0] === 'number' &&
typeof arg[1] === 'number'
)
}
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type AppConfig = {
primaryColor: string
}
map: {
find_address_in_distance: number
center: [number, number]
maxBounds: [[number, number], [number, number]]
}
Expand Down

0 comments on commit 9216c1b

Please sign in to comment.