Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/google maps link #10003

Closed
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
042702c
Add Google Maps link for facility location and update facility data type
rahulharpal1603 Jan 15, 2025
fa95cbc
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
rahulharpal1603 Jan 15, 2025
1c1731e
Remove Google Maps entries from localization files and clean up conso…
rahulharpal1603 Jan 16, 2025
8131ced
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
rahulharpal1603 Jan 21, 2025
8e375be
Fix: change latitude and longitude types from string to number in Fac…
rahulharpal1603 Jan 21, 2025
dfd83e9
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
rahulharpal1603 Jan 22, 2025
c0109a7
Added conditional link handling based on whether device is Android or…
rahulharpal1603 Jan 22, 2025
5671e1e
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
rahulharpal1603 Jan 31, 2025
c93b037
Create separate component for Facility Maps link and add it to both a…
rahulharpal1603 Jan 31, 2025
88e05ae
add props validation for coordinates.
rahulharpal1603 Jan 31, 2025
4c019c1
Fix TS errors
rahulharpal1603 Jan 31, 2025
dca61e3
improve props validation
rahulharpal1603 Jan 31, 2025
3378e84
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
rahulharpal1603 Jan 31, 2025
15d9f07
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
rahulharpal1603 Feb 5, 2025
a8a1032
fixed non-existent coordinates problem
rahulharpal1603 Feb 5, 2025
0344faf
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
rahulharpal1603 Feb 5, 2025
4b72654
using Number.isNaN
rahulharpal1603 Feb 5, 2025
90d859c
Merge branch 'develop' into feat/Google-Maps-Link
rahulharpal1603 Feb 6, 2025
81f6b71
Remove unnecessary blank line in FacilityHome component
rahulharpal1603 Feb 6, 2025
95eef75
Merge branch 'develop' into feat/Google-Maps-Link
rahulharpal1603 Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve props validation
rahulharpal1603 committed Jan 31, 2025

Verified

This commit was signed with the committer’s verified signature.
florianduros Florian Duros
commit dca61e3623b6f95ed38a8f1f52307e17a2961c66
19 changes: 13 additions & 6 deletions src/components/Facility/FacilityMapsLink.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { SquareArrowOutUpRight } from "lucide-react";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";

import { isAndroidDevice } from "@/Utils/utils";

const useValidateCoordinates = (latitude: number, longitude: number) => {
useEffect(() => {
if (latitude < -90 || latitude > 90) {
console.error("Invalid latitude. Must be between -90 and 90 degrees.");
}
if (longitude < -180 || longitude > 180) {
console.error("Invalid longitude. Must be between -180 and 180 degrees.");
}
}, [latitude, longitude]);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance coordinate validation.

The current validation approach using console.error in a hook has several limitations:

  1. Console messages aren't suitable for production environments
  2. Validation doesn't prevent invalid coordinates from being used
  3. Validation logic isn't reusable outside React components

Consider this alternative approach:

// utils/coordinates.ts
export class InvalidCoordinateError extends Error {
  constructor(message: string) {
    super(message);
    this.name = 'InvalidCoordinateError';
  }
}

export const validateCoordinates = (latitude: number, longitude: number) => {
  if (latitude < -90 || latitude > 90) {
    throw new InvalidCoordinateError("Invalid latitude. Must be between -90 and 90 degrees.");
  }
  if (longitude < -180 || longitude > 180) {
    throw new InvalidCoordinateError("Invalid longitude. Must be between -180 and 180 degrees.");
  }
  return { latitude, longitude };
};

// FacilityMapsLink.tsx
const useValidateCoordinates = (latitude: number, longitude: number) => {
  useEffect(() => {
    try {
      validateCoordinates(latitude, longitude);
    } catch (error) {
      // Log to error monitoring service
      console.error(error);
    }
  }, [latitude, longitude]);
};


export const FacilityMapsLink = ({
latitude,
longitude,
}: {
latitude: number & { __brand: "ValidLatitude" };
longitude: number & { __brand: "ValidLongitude" };
}) => {
if (latitude < -90 || latitude > 90) {
throw new Error("Invalid latitude. Must be between -90 and 90 degrees.");
}
if (longitude < -180 || longitude > 180) {
throw new Error("Invalid longitude. Must be between -180 and 180 degrees.");
}
useValidateCoordinates(latitude, longitude);
const { t } = useTranslation();
const href = isAndroidDevice
? `geo:0,0?q=${latitude},${longitude}`