userGrid joinDate field removed
This commit is contained in:
parent
02879cefd1
commit
1a2bd83e8d
@ -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,
|
||||
|
||||
@ -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<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 () => {
|
||||
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,
|
||||
}}
|
||||
>
|
||||
<Text style={styles.infoLabel}>Gym</Text>
|
||||
<Text style={styles.infoLabel}>
|
||||
Gym{" "}
|
||||
{currentGymName
|
||||
? `(Current: ${currentGymName})`
|
||||
: currentGymId
|
||||
? `(Current: ${currentGymId})`
|
||||
: "(Current: None)"}
|
||||
</Text>
|
||||
<TouchableOpacity onPress={loadGyms}>
|
||||
<Text style={{ color: theme.colors.primary }}>
|
||||
Refresh Gyms
|
||||
|
||||
@ -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 = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user