userGrid joinDate field removed

This commit is contained in:
echo 2025-12-26 19:48:36 +01:00
parent 02879cefd1
commit 1a2bd83e8d
3 changed files with 62 additions and 13 deletions

View File

@ -245,15 +245,15 @@ export function UserGrid({
}, },
minWidth: 180, minWidth: 180,
}, },
{ // {
headerName: "Join Date", // headerName: "Join Date",
valueGetter: (params) => // valueGetter: (params) =>
params.data?.client?.joinDate || params.data?.createdAt, // params.data?.client?.joinDate || params.data?.createdAt,
filter: "agDateColumnFilter", // filter: "agDateColumnFilter",
sortable: true, // sortable: true,
valueFormatter: (params: any) => formatDate(new Date(params.value)), // valueFormatter: (params: any) => formatDate(new Date(params.value)),
minWidth: 120, // minWidth: 120,
}, // },
{ {
headerName: "Last Visit", headerName: "Last Visit",
valueGetter: (params) => params.data?.client?.lastVisit, valueGetter: (params) => params.data?.client?.lastVisit,

View File

@ -15,7 +15,7 @@ import { LinearGradient } from "expo-linear-gradient";
import { theme } from "../../styles/theme"; import { theme } from "../../styles/theme";
import { AnimatedButton } from "../../components/AnimatedButton"; import { AnimatedButton } from "../../components/AnimatedButton";
import { GradientBackground } from "../../components/GradientBackground"; import { GradientBackground } from "../../components/GradientBackground";
import { useState } from "react"; import { useState, useEffect } from "react";
import { API_BASE_URL, API_ENDPOINTS } from "../../config/api"; import { API_BASE_URL, API_ENDPOINTS } from "../../config/api";
export default function ProfileScreen() { export default function ProfileScreen() {
@ -45,6 +45,24 @@ export default function ProfileScreen() {
>([]); >([]);
const [gymsLoading, setGymsLoading] = useState(false); const [gymsLoading, setGymsLoading] = useState(false);
const [selectedGymId, setSelectedGymId] = useState<string | null>(null); const [selectedGymId, setSelectedGymId] = useState<string | null>(null);
const [currentGymId, setCurrentGymId] = useState<string | null>(null);
const [currentGymName, setCurrentGymName] = useState<string | null>(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 () => { const loadGyms = async () => {
try { try {
@ -88,7 +106,18 @@ export default function ProfileScreen() {
setGyms([]); setGyms([]);
return; 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) { } catch (err) {
console.error("Failed to fetch gyms:", err); console.error("Failed to fetch gyms:", err);
setGyms([]); 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( Alert.alert(
"Success", "Success",
selectedGymId ? "Gym selected successfully" : "Proceeding without gym", selectedGymId ? "Gym selected successfully" : "Proceeding without gym",
@ -255,7 +297,14 @@ export default function ProfileScreen() {
padding: 12, padding: 12,
}} }}
> >
<Text style={styles.infoLabel}>Gym</Text> <Text style={styles.infoLabel}>
Gym{" "}
{currentGymName
? `(Current: ${currentGymName})`
: currentGymId
? `(Current: ${currentGymId})`
: "(Current: None)"}
</Text>
<TouchableOpacity onPress={loadGyms}> <TouchableOpacity onPress={loadGyms}>
<Text style={{ color: theme.colors.primary }}> <Text style={{ color: theme.colors.primary }}>
Refresh Gyms Refresh Gyms

View File

@ -1,5 +1,5 @@
export const API_BASE_URL = __DEV__ export const API_BASE_URL = __DEV__
? "https://a4db649a0973.ngrok-free.app" ? "https://1e98d7618300.ngrok-free.app"
: "https://your-production-url.com"; : "https://your-production-url.com";
export const API_ENDPOINTS = { export const API_ENDPOINTS = {