mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
Update member IDs and refactor geolocation
Adjust team data and improve geolocation handling. In app/(dashboard)/hats-team/page.tsx several TeamMember IDs were updated and a new member (Teddy Setiawan) was added; pastMembers IDs were also adjusted. In app/(dashboard)/presence-v2/components/FormComponent.tsx geolocation logic was refactored: moved PositionOptions constant outside the component, added useCallback for displayLocation, successCallback, and errorCallback, fixed useEffect dependencies to use stable callbacks, reduced noisy toasts on non-critical errors, and corrected an error-toast formatting issue. Also added useCallback to imports and minor formatting cleanups.
This commit is contained in:
@@ -18,35 +18,42 @@ interface TeamMember {
|
||||
|
||||
const activeMembers: TeamMember[] = [
|
||||
{
|
||||
id: "9",
|
||||
id: "2",
|
||||
name: "Stevanus Akbar Alexander",
|
||||
role: "Manager",
|
||||
joinDate: "2013-01-02T00:00:00.000Z",
|
||||
avatar: "images/avatar/12345667892-avatar.png"
|
||||
},
|
||||
{
|
||||
id: "19",
|
||||
id: "6",
|
||||
name: "Luthfi Aditama",
|
||||
role: "Team Leader",
|
||||
joinDate: "2017-04-04T00:00:00.000Z",
|
||||
avatar: "images/avatar/04021704068-avatar.png"
|
||||
},
|
||||
{
|
||||
id: "20",
|
||||
id: "7",
|
||||
name: "Mohamad Saeful Ihsan",
|
||||
role: "Team Leader",
|
||||
joinDate: "2017-05-15T00:00:00.000Z",
|
||||
avatar: "images/avatar/04021705070-avatar.png"
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
id: "14",
|
||||
name: "Ichsan Kurniawan",
|
||||
role: "Front End Programmer",
|
||||
joinDate: "2019-10-23T00:00:00.000Z",
|
||||
avatar: "images/avatar/04031910149-avatar.png"
|
||||
},
|
||||
{
|
||||
id: "8",
|
||||
id: "18",
|
||||
name: "Teddy Setiawan",
|
||||
role: "Backend Programmer",
|
||||
joinDate: "2022-10-23T00:00:00.000Z",
|
||||
avatar: "images/avatar/04032202209-avatar.png"
|
||||
},
|
||||
{
|
||||
id: "36",
|
||||
name: "Amalia Mandawati",
|
||||
role: "Technical Writer",
|
||||
joinDate: "2024-10-07T00:00:00.000Z",
|
||||
@@ -56,7 +63,7 @@ const activeMembers: TeamMember[] = [
|
||||
|
||||
const pastMembers: TeamMember[] = [
|
||||
{
|
||||
id: "2",
|
||||
id: "21",
|
||||
name: "Evan Arifial Hidayat",
|
||||
role: "Mobile Programmer",
|
||||
joinDate: "2022-04-01T00:00:00.000Z",
|
||||
@@ -64,7 +71,7 @@ const pastMembers: TeamMember[] = [
|
||||
avatar: "images/avatar/04032204216-avatar.png",
|
||||
},
|
||||
{
|
||||
id: "10",
|
||||
id: "25",
|
||||
name: "Nofita Mahfudiyah",
|
||||
role: "Technical Writer",
|
||||
joinDate: "2022-09-22T00:00:00.000Z",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { FC, useEffect, useState } from 'react';
|
||||
import { FC, useCallback, useEffect, useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { Camera as CameraIcon } from 'lucide-react';
|
||||
@@ -14,6 +14,13 @@ import { Icons } from '@/components/Icons';
|
||||
import { toast } from 'sonner';
|
||||
import { Label } from '@/components/ui/label';
|
||||
|
||||
// Move options OUTSIDE the component so it doesn't recreate on every render
|
||||
const GEOLOCATION_OPTIONS: PositionOptions = {
|
||||
enableHighAccuracy: true,
|
||||
timeout: 10000,
|
||||
maximumAge: 0
|
||||
};
|
||||
|
||||
type Props = {
|
||||
isCheckout?: boolean
|
||||
workingStatusList: any[]
|
||||
@@ -37,20 +44,34 @@ const FormComponent: FC<Props> = ({ isCheckout, workingStatusList }) => {
|
||||
const router = useRouter()
|
||||
const axios = useAxiosAuth()
|
||||
|
||||
const options: PositionOptions = {
|
||||
enableHighAccuracy: true,
|
||||
timeout: 10000,
|
||||
maximumAge: 0
|
||||
};
|
||||
// 1. Wrap displayLocation in useCallback
|
||||
const displayLocation = useCallback(async (latitude: number, longitude: number) => {
|
||||
try {
|
||||
const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2&zoom=13`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
console.log(data?.display_name)
|
||||
setLocationName(data?.display_name)
|
||||
} else {
|
||||
// Optional: Reduce noise by not toasting on minor network errors during typing
|
||||
console.warn(`${res.status} ${res.statusText}`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching location name", error)
|
||||
}
|
||||
}, []);
|
||||
|
||||
const successCallback = (position: GeolocationPosition) => {
|
||||
// 2. Wrap successCallback in useCallback
|
||||
const successCallback = useCallback((position: GeolocationPosition) => {
|
||||
const x = position.coords.latitude;
|
||||
const y = position.coords.longitude;
|
||||
setLatitude(x); setLongitude(y)
|
||||
setLatitude(x);
|
||||
setLongitude(y);
|
||||
displayLocation(x, y);
|
||||
};
|
||||
}, [displayLocation]); // Depends on displayLocation
|
||||
|
||||
const errorCallback = (error: GeolocationPositionError) => {
|
||||
// 3. Wrap errorCallback in useCallback
|
||||
const errorCallback = useCallback((error: GeolocationPositionError) => {
|
||||
let errorMessage = 'Unknown error';
|
||||
switch (error.code) {
|
||||
case 1:
|
||||
@@ -63,28 +84,19 @@ const FormComponent: FC<Props> = ({ isCheckout, workingStatusList }) => {
|
||||
errorMessage = 'Timeout';
|
||||
break;
|
||||
}
|
||||
// Only toast if it's a serious permission issue, or throttle it
|
||||
toast.warning("Failed to fetch geolocation, reason: " + errorMessage)
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 4. Update useEffect dependencies
|
||||
useEffect(() => {
|
||||
if (!navigator.geolocation) {
|
||||
toast.warning('Geolocation not available in your apps')
|
||||
return
|
||||
}
|
||||
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
|
||||
}, [successCallback])
|
||||
|
||||
|
||||
const displayLocation = async (latitude: number, longitude: number) => {
|
||||
const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2&zoom=13`)
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
console.log(data?.display_name)
|
||||
setLocationName(data?.display_name)
|
||||
} else {
|
||||
toast.warning(`${res.status} ${res.statusText}`)
|
||||
}
|
||||
};
|
||||
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, GEOLOCATION_OPTIONS);
|
||||
}, [successCallback, errorCallback]); // Now these dependencies are stable
|
||||
|
||||
const handleReceivePhoto = (photo: string, landscape?: boolean, w?: number, h?: number) => {
|
||||
setOrientation(w! > h! ? 'landscape' : w === h ? 'square' : 'portrait')
|
||||
@@ -135,7 +147,7 @@ const FormComponent: FC<Props> = ({ isCheckout, workingStatusList }) => {
|
||||
router.refresh()
|
||||
}).catch(error => {
|
||||
setIsLoading(false)
|
||||
toast.error(`${title} failed`, { description: `(${error.response?.data?.code || error.response?.status || '-'}) ${error.response?.data?.message || error.response?.statusText || error.message}}` })
|
||||
toast.error(`${title} failed`, { description: `(${error.response?.data?.code || error.response?.status || '-'}) ${error.response?.data?.message || error.response?.statusText || error.message}` })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user