Skip to content

Commit 18c9c79

Browse files
authored
Connect Find Help cards and map markers to organisation pages (#45)
1 parent 191561d commit 18c9c79

File tree

6 files changed

+80
-40
lines changed

6 files changed

+80
-40
lines changed

src/components/FindHelp/FindHelpResults.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface MapMarker {
2525
lng: number;
2626
title: string;
2727
organisation?: string;
28-
link?: string;
28+
organisationSlug: string;
2929
serviceName?: string;
3030
distanceKm?: number;
3131
icon?: string;
@@ -118,6 +118,7 @@ export default function FindHelpResults({ providers }: Props) {
118118
lng: s.lng,
119119
title: s.name,
120120
organisation: s.organisation,
121+
organisationSlug: s.organisationSlug,
121122
serviceName: s.name,
122123
distanceKm: s.distance,
123124
}));
@@ -128,6 +129,7 @@ export default function FindHelpResults({ providers }: Props) {
128129
lat: location.lat,
129130
lng: location.lng,
130131
title: 'You are here',
132+
organisationSlug: 'user-location',
131133
icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
132134
});
133135
}
@@ -224,4 +226,4 @@ export default function FindHelpResults({ providers }: Props) {
224226
)}
225227
</section>
226228
);
227-
}
229+
}

src/components/FindHelp/ServiceCard.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import React from 'react';
4+
import Link from 'next/link';
45

56
export interface Service {
67
id: string;
@@ -9,6 +10,7 @@ export interface Service {
910
subCategory: string;
1011
description: string;
1112
organisation?: string;
13+
organisationSlug?: string;
1214
openTimes?: { day: string; start: string; end: string }[];
1315
clientGroups?: string[];
1416
lat?: number;
@@ -20,23 +22,25 @@ interface ServiceCardProps {
2022
}
2123

2224
export default function ServiceCard({ service }: ServiceCardProps) {
25+
const destination = service.organisationSlug
26+
? `/find-help/organisation/${service.organisationSlug}`
27+
: '#';
28+
2329
return (
24-
<div className="border-none p-0 shadow-none bg-transparent">
25-
<h2 className="text-lg font-semibold mb-1">
26-
{service.name}
27-
</h2>
30+
<Link
31+
href={destination}
32+
className="block border rounded-lg p-4 shadow-md hover:shadow-lg transition-shadow bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-brand-a"
33+
aria-label={`View details for ${service.name}`}
34+
>
35+
<h2 className="text-lg font-semibold mb-1">{service.name}</h2>
2836

2937
{service.organisation && (
30-
<p className="text-sm text-gray-600 mb-2">
31-
{service.organisation}
32-
</p>
38+
<p className="text-sm text-gray-600 mb-2">{service.organisation}</p>
3339
)}
3440

35-
<p className="text-gray-800 mb-2">
36-
{service.description}
37-
</p>
41+
<p className="text-gray-800 mb-2">{service.description}</p>
3842

39-
<p className="text-sm text-gray-500 mb-2">
43+
<p className="text-sm text-gray-500 mb-1">
4044
Category: {service.category}
4145
</p>
4246

@@ -47,7 +51,10 @@ export default function ServiceCard({ service }: ServiceCardProps) {
4751
{service.clientGroups && service.clientGroups.length > 0 && (
4852
<div className="text-sm mt-2">
4953
{service.clientGroups.map((group, idx) => (
50-
<span key={idx} className="inline-block bg-gray-100 px-2 py-1 mr-2 rounded">
54+
<span
55+
key={idx}
56+
className="inline-block bg-gray-100 px-2 py-1 mr-2 rounded"
57+
>
5158
{group}
5259
</span>
5360
))}
@@ -63,6 +70,6 @@ export default function ServiceCard({ service }: ServiceCardProps) {
6370
))}
6471
</div>
6572
)}
66-
</div>
73+
</Link>
6774
);
6875
}

src/components/Homepage/HomepageMap.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function HomepageMap() {
2424
title: loc.name,
2525
icon: '/assets/img/map-pin.png',
2626
link: `/${loc.key}`,
27+
organisationSlug: `homepage-${loc.key}`
2728
}));
2829
}, []);
2930

src/components/MapComponent/GoogleMap.tsx

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ interface Marker {
77
lat: number;
88
lng: number;
99
title: string;
10+
organisationSlug: string; // ✅ must match field used in ServiceCard
1011
icon?: string;
1112
organisation?: string;
1213
serviceName?: string;
1314
distanceKm?: number;
14-
link?: string;
1515
}
1616

1717
interface Props {
@@ -52,7 +52,17 @@ export default function GoogleMap({ center, markers, zoom }: Props) {
5252
const newMarkers: google.maps.Marker[] = [];
5353

5454
markers.forEach((markerData) => {
55-
const { lat, lng, title, icon, organisation, serviceName, distanceKm, link } = markerData;
55+
const {
56+
id,
57+
lat,
58+
lng,
59+
title,
60+
icon,
61+
organisation,
62+
serviceName,
63+
distanceKm,
64+
organisationSlug, // ✅ corrected
65+
} = markerData;
5666

5767
const gMarker = new google.maps.Marker({
5868
position: { lat, lng },
@@ -61,29 +71,39 @@ export default function GoogleMap({ center, markers, zoom }: Props) {
6171
icon: icon || undefined,
6272
});
6373

64-
if (link) {
65-
gMarker.addListener('click', () => {
66-
window.location.href = link;
67-
});
68-
} else {
69-
const htmlContent = `
70-
<div style="font-size:14px;max-width:220px;">
71-
<strong>${organisation ? `<a href="/organisation-slug" target="_blank" rel="noopener noreferrer">${organisation}</a>` : 'Unknown Organisation'}</strong><br/>
72-
${serviceName ?? 'Unnamed service'}<br/>
73-
${distanceKm?.toFixed(1) ?? '?'} km away
74-
</div>
75-
`;
76-
77-
const infoWindow = new google.maps.InfoWindow({ content: htmlContent });
78-
79-
gMarker.addListener('click', () => {
80-
if (infoWindowRef.current) {
81-
infoWindowRef.current.close();
74+
const destination = `/find-help/organisation/${organisationSlug}`;
75+
const infoId = `info-${id}`;
76+
77+
const htmlContent = `
78+
<div
79+
id="${infoId}"
80+
style="font-size:14px;max-width:220px;cursor:pointer;padding:4px;"
81+
>
82+
<strong style="color:#0b9b75;">${organisation ?? 'Unknown Organisation'}</strong><br/>
83+
${serviceName ?? 'Unnamed service'}<br/>
84+
${distanceKm?.toFixed(1) ?? '?'} km away
85+
</div>
86+
`;
87+
88+
const infoWindow = new google.maps.InfoWindow({ content: htmlContent });
89+
90+
gMarker.addListener('click', () => {
91+
if (infoWindowRef.current) {
92+
infoWindowRef.current.close();
93+
}
94+
95+
infoWindowRef.current = infoWindow;
96+
infoWindow.open(map, gMarker);
97+
98+
google.maps.event.addListenerOnce(infoWindow, 'domready', () => {
99+
const el = document.getElementById(infoId);
100+
if (el) {
101+
el.addEventListener('click', () => {
102+
window.location.href = destination;
103+
});
82104
}
83-
infoWindowRef.current = infoWindow;
84-
infoWindow.open(map, gMarker);
85105
});
86-
}
106+
});
87107

88108
newMarkers.push(gMarker);
89109
});

src/components/OrganisationPage/OrganisationLocations.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ export default function OrganisationLocations({ organisation }: Props) {
1717

1818
const center = { lat: organisation.latitude, lng: organisation.longitude };
1919
const markers = [
20-
{ id: organisation.id, lat: organisation.latitude, lng: organisation.longitude, title: organisation.name },
20+
{
21+
id: organisation.id,
22+
lat: organisation.latitude,
23+
lng: organisation.longitude,
24+
title: organisation.name,
25+
organisationSlug: organisation.slug || 'org-loc-default' // ✅ dummy fallback slug
26+
},
2127
];
2228

2329
return (
@@ -26,4 +32,4 @@ export default function OrganisationLocations({ organisation }: Props) {
2632
<GoogleMap center={center} markers={markers} zoom={14} />
2733
</section>
2834
);
29-
}
35+
}

test-results/.last-run.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"status": "passed",
3+
"failedTests": []
4+
}

0 commit comments

Comments
 (0)