From 1a2bd83e8dfa2f039cfc7cf050f526cfc27af7c0 Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 26 Dec 2025 19:48:36 +0100 Subject: [PATCH] userGrid joinDate field removed --- apps/admin/src/components/users/UserGrid.tsx | 18 +++---- apps/mobile/src/app/(tabs)/profile.tsx | 55 ++++++++++++++++++-- apps/mobile/src/config/api.ts | 2 +- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/apps/admin/src/components/users/UserGrid.tsx b/apps/admin/src/components/users/UserGrid.tsx index d9bc6b3..4450d73 100644 --- a/apps/admin/src/components/users/UserGrid.tsx +++ b/apps/admin/src/components/users/UserGrid.tsx @@ -245,15 +245,15 @@ export function UserGrid({ }, minWidth: 180, }, - { - headerName: "Join Date", - valueGetter: (params) => - params.data?.client?.joinDate || params.data?.createdAt, - filter: "agDateColumnFilter", - sortable: true, - valueFormatter: (params: any) => formatDate(new Date(params.value)), - minWidth: 120, - }, + // { + // headerName: "Join Date", + // valueGetter: (params) => + // params.data?.client?.joinDate || params.data?.createdAt, + // filter: "agDateColumnFilter", + // sortable: true, + // valueFormatter: (params: any) => formatDate(new Date(params.value)), + // minWidth: 120, + // }, { headerName: "Last Visit", valueGetter: (params) => params.data?.client?.lastVisit, diff --git a/apps/mobile/src/app/(tabs)/profile.tsx b/apps/mobile/src/app/(tabs)/profile.tsx index 7a2d740..e287b03 100644 --- a/apps/mobile/src/app/(tabs)/profile.tsx +++ b/apps/mobile/src/app/(tabs)/profile.tsx @@ -15,7 +15,7 @@ import { LinearGradient } from "expo-linear-gradient"; import { theme } from "../../styles/theme"; import { AnimatedButton } from "../../components/AnimatedButton"; import { GradientBackground } from "../../components/GradientBackground"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { API_BASE_URL, API_ENDPOINTS } from "../../config/api"; export default function ProfileScreen() { @@ -45,6 +45,24 @@ export default function ProfileScreen() { >([]); const [gymsLoading, setGymsLoading] = useState(false); const [selectedGymId, setSelectedGymId] = useState(null); + const [currentGymId, setCurrentGymId] = useState(null); + const [currentGymName, setCurrentGymName] = useState(null); + + useEffect(() => { + const gid = + ((user?.publicMetadata as any)?.gymId as string | undefined) ?? null; + setCurrentGymId(gid ?? null); + if (gid && gyms.length > 0) { + const g = gyms.find((x) => x.id === gid); + setCurrentGymName(g?.name ?? null); + if (selectedGymId === null) setSelectedGymId(gid); + } + }, [user?.publicMetadata, gyms]); + + // Auto-load gyms on mount + useEffect(() => { + loadGyms(); + }, []); const loadGyms = async () => { try { @@ -88,7 +106,18 @@ export default function ProfileScreen() { setGyms([]); return; } - setGyms(Array.isArray(data) ? data : []); + const list = Array.isArray(data) ? data : []; + setGyms(list); + const gid = + currentGymId ?? + ((user?.publicMetadata as any)?.gymId as string | undefined) ?? + null; + if (gid) { + const g = list.find((x: any) => x.id === gid); + setCurrentGymId(gid); + setCurrentGymName(g?.name ?? null); + if (selectedGymId === null) setSelectedGymId(gid); + } } catch (err) { console.error("Failed to fetch gyms:", err); setGyms([]); @@ -139,6 +168,19 @@ export default function ProfileScreen() { ); } } + // Update current gym state for immediate UI reflection + setCurrentGymId(selectedGymId); + setCurrentGymName( + selectedGymId + ? (gyms.find((g) => g.id === selectedGymId)?.name ?? null) + : null, + ); + // Attempt to reload Clerk user metadata so current gym reflects server state + try { + await (user as any)?.reload?.(); + } catch (e) { + console.log("Profile.handleApplyGym: failed to reload user", e); + } Alert.alert( "Success", selectedGymId ? "Gym selected successfully" : "Proceeding without gym", @@ -255,7 +297,14 @@ export default function ProfileScreen() { padding: 12, }} > - Gym + + Gym{" "} + {currentGymName + ? `(Current: ${currentGymName})` + : currentGymId + ? `(Current: ${currentGymId})` + : "(Current: None)"} + Refresh Gyms diff --git a/apps/mobile/src/config/api.ts b/apps/mobile/src/config/api.ts index da96e2b..c8474d1 100644 --- a/apps/mobile/src/config/api.ts +++ b/apps/mobile/src/config/api.ts @@ -1,5 +1,5 @@ export const API_BASE_URL = __DEV__ - ? "https://a4db649a0973.ngrok-free.app" + ? "https://1e98d7618300.ngrok-free.app" : "https://your-production-url.com"; export const API_ENDPOINTS = {