diff --git a/distribution_fe/app/(dashboard)/sales-visits/_components/sales-visits-client.tsx b/distribution_fe/app/(dashboard)/sales-visits/_components/sales-visits-client.tsx
index b4ad638..b652aac 100644
--- a/distribution_fe/app/(dashboard)/sales-visits/_components/sales-visits-client.tsx
+++ b/distribution_fe/app/(dashboard)/sales-visits/_components/sales-visits-client.tsx
@@ -13,8 +13,8 @@ import {
SelectValue,
} from '@/components/ui/select'
import { toast } from '@/components/ui/toast'
-import { routes as routesApi, stores as storesApi, getApiError, getPaginatedItems } from '@/lib/api/index'
-import type { RouteResponse, StoreResponse, RouteVisitResponse } from '@/types/api'
+import { routes as routesApi, stores as storesApi, users as usersApi, getApiError, getPaginatedItems } from '@/lib/api/index'
+import type { RouteResponse, StoreResponse, RouteVisitResponse, UserResponse } from '@/types/api'
type VisitState = 'idle' | 'checked-in' | 'checked-out'
@@ -36,11 +36,16 @@ export function SalesVisitsClient() {
const [visitState, setVisitState] = useState>({})
const [deviationByStore, setDeviationByStore] = useState>({})
const [busyStoreId, setBusyStoreId] = useState(null)
+ const [usersList, setUsersList] = useState([])
+ const [checkedInByUserId, setCheckedInByUserId] = useState('')
useEffect(() => {
routesApi.list({ page: 1, pageSize: 200 })
.then((res) => setRouteList(getPaginatedItems(res).filter((r) => r.isActive)))
.catch(() => toast.add({ title: 'Failed to load routes', type: 'error' }))
+ usersApi.list({ pageSize: 200 })
+ .then((res) => setUsersList(getPaginatedItems(res)))
+ .catch(() => toast.add({ title: 'Failed to load users', type: 'error' }))
}, [])
useEffect(() => {
@@ -60,6 +65,10 @@ export function SalesVisitsClient() {
}, [selectedRouteId])
async function handleCheckIn(store: StoreResponse) {
+ if (!checkedInByUserId) {
+ toast.add({ title: 'Select who is checking in first', type: 'error' })
+ return
+ }
setBusyStoreId(store.id)
try {
const position = await getCurrentPosition()
@@ -67,6 +76,7 @@ export function SalesVisitsClient() {
storeId: store.id,
latitude: position.coords.latitude,
longitude: position.coords.longitude,
+ checkedInByUserId,
})
setVisitState((prev) => ({ ...prev, [store.id]: 'checked-in' }))
setDeviationByStore((prev) => ({ ...prev, [store.id]: result.isDeviationFlagged }))
@@ -105,20 +115,41 @@ export function SalesVisitsClient() {
-
-
-
+
+
+
+
+
+
+
+
+
+
+ Temporary — required until auth resolves the logged-in user automatically.
+
+
{loadingStores &&
Loading stores…
}
diff --git a/distribution_fe/lib/api/master.ts b/distribution_fe/lib/api/master.ts
index 69c7df2..97a0c0e 100644
--- a/distribution_fe/lib/api/master.ts
+++ b/distribution_fe/lib/api/master.ts
@@ -156,7 +156,7 @@ export const routes = {
assignOwner: (id: string, salesRepId: string) =>
api.put
(`/routes/${id}/owner`, { salesRepId }).then(r => r.data),
- checkIn: (id: string, body: { storeId: string; latitude: number; longitude: number }) =>
+ checkIn: (id: string, body: { storeId: string; latitude: number; longitude: number; checkedInByUserId: string }) =>
api.post(`/routes/${id}/visits/check-in`, body).then(r => r.data),
checkOut: (id: string, body: { storeId: string }) =>