Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
fix(#35): change restaurant address structure
Browse files Browse the repository at this point in the history
  • Loading branch information
floriaaan authored and Anatole-Godard committed Feb 3, 2024
1 parent c78c1cf commit 555f469
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
4 changes: 2 additions & 2 deletions apps/web/app/(normal)/account/orders/[id]/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const OrderStatusMap = (order: Order) => {

const { restaurants } = useLocation();
const restaurant = restaurants.find((r) => r.id === order.restaurant_id);
const { locationList: r_location } = restaurant || {};
const [r_lat, r_lng] = r_location || [0, 0];
const { address: r_location } = restaurant || {};
const [r_lat, r_lng] = [r_location?.lat, r_location?.lng] || [0, 0];

// todo: move getting gps coordinates of address to service instead of client
const { address } = order.delivery;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(normal)/checkout/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default function CheckoutPage() {
</Button>
<Button asChild>
<a
href={`https://www.google.com/maps?q=${restaurant.locationList[0]},${restaurant.locationList[1]}`}
href={`https://www.google.com/maps?q=${restaurant.address.lat},${restaurant.address.lng}`}
target="_blank"
rel="noopener noreferrer"
>
Expand Down
6 changes: 3 additions & 3 deletions apps/web/app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default function AdminHome() {
<div className="h-96">
<Map
center={{
latitude: restaurantList[0].locationList[0] || 0,
longitude: restaurantList[0].locationList[1] || 0,
latitude: restaurantList[0].address.lat || 0,
longitude: restaurantList[0].address.lng || 0,
}}
>
{[
Expand All @@ -32,7 +32,7 @@ export default function AdminHome() {
</Marker>
))}
{restaurantList.map((r) => (
<Marker key={r.id} latitude={r.locationList[0]} longitude={r.locationList[1]} anchor="bottom">
<Marker key={r.id} latitude={r.address.lat} longitude={r.address.lng} anchor="bottom">
<RestaurantPin />
</Marker>
))}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/components/location/restaurant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const LocationRestaurant = ({
getDistance(
{ latitude: lat, longitude: lng },
{
latitude: restaurant.locationList[0],
longitude: restaurant.locationList[1],
latitude: restaurant.address.lat,
longitude: restaurant.address.lng,
},
) / 1000
).toFixed(1)} km`}
Expand Down
20 changes: 16 additions & 4 deletions apps/web/constants/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,14 @@ export const restaurantList: Restaurant[] = [
{
id: "restaurant_id:1",
name: "Rouen Gros Horloge",
address: "1 Rue du Gros Horloge, 76000 Rouen",
locationList: [49.440459, 1.094853],
address: {
lat: 49.440459,
lng: 1.094853,
street: "1 Rue du Gros Horloge",
city: "Rouen",
zipcode: "76000",
country: "France",
},
openinghoursList: ["11h30 - 14h30 / 18h30 - 22h30"],
phone: "02 35 71 00 00",
useridsList: [],
Expand All @@ -201,8 +207,14 @@ export const restaurantList: Restaurant[] = [
{
id: "restaurant_id:2",
name: "Rouen Pierre Corneille",
address: "76 Rue Pierre Corneille, 76000 Rouen",
locationList: [49.442459, 1.094853],
address: {
lat: 49.442459,
lng: 1.094853,
street: "76 Rue Pierre Corneille",
city: "Rouen",
zipcode: "76000",
country: "France",
},
openinghoursList: ["11h30 - 14h30 / 18h30 - 22h30"],
phone: "02 35 71 00 00",
useridsList: [],
Expand Down
2 changes: 1 addition & 1 deletion apps/web/hooks/useLocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const LocationProvider = ({ children }: { children: React.ReactNode }) =>
queryFn: async () => {
const res = await fetchAPI(`/api/restaurant/by-location`, undefined, {
method: "POST",
body: JSON.stringify({ locationList: [lat, lng] }),
body: JSON.stringify({ lat, lng }),
});
const body = await res.json();
return body.restaurantsList;
Expand Down
13 changes: 11 additions & 2 deletions apps/web/types/restaurant.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
export type Restaurant = {
id: string;
name: string;
address: string;
locationList: number[];
address: Address;
openinghoursList: string[];
description?: string;
phone: string;
useridsList: string[];
createdat: string;
updatedat: string;
};

export type Address = {
lat: number;
lng: number;

street?: string;
city?: string;
zipcode?: string;
country?: string;
};

0 comments on commit 555f469

Please sign in to comment.