standardize mobile api transport for gyms and core services
This commit is contained in:
1 parent
c36cad9c54
commit
80110acbf7
8 files changed
+322
-386
No files matched your search
@@ -12,7 +12,7 @@ import {
|
||||
import { useUser, useAuth } from "@clerk/clerk-expo";
|
||||
import { useRouter } from "expo-router";
|
||||
import { fitnessProfileApi } from "@/api/fitnessProfile";
|
||||
import { API_BASE_URL } from "@/config/api";
|
||||
import { gymsApi, type Gym } from "@/api/gyms";
|
||||
import log from "../../utils/logger";
|
||||
|
||||
export default function OnboardingScreen() {
|
||||
@@ -20,9 +20,7 @@ export default function OnboardingScreen() {
|
||||
const { getToken } = useAuth();
|
||||
const router = useRouter();
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [gyms, setGyms] = useState<
|
||||
Array<{ id: string; name: string; location?: string }>
|
||||
>([]);
|
||||
const [gyms, setGyms] = useState<Gym[]>([]);
|
||||
const [gymsLoading, setGymsLoading] = useState<boolean>(false);
|
||||
const [selectedGymId, setSelectedGymId] = useState<string | null>(null);
|
||||
|
||||
@@ -31,13 +29,8 @@ export default function OnboardingScreen() {
|
||||
try {
|
||||
setGymsLoading(true);
|
||||
const token = await getToken();
|
||||
const res = await fetch(`${API_BASE_URL}/api/gyms`, {
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
|
||||
});
|
||||
const data = await res.json();
|
||||
if (Array.isArray(data)) {
|
||||
setGyms(data);
|
||||
}
|
||||
const data = await gymsApi.getGyms(token);
|
||||
setGyms(data);
|
||||
} catch (e) {
|
||||
log.error("Failed to fetch gyms", e);
|
||||
} finally {
|
||||
@@ -82,14 +75,7 @@ export default function OnboardingScreen() {
|
||||
// If gym was selected or cleared, patch user's gym selection first
|
||||
// selectedGymId: string gym id, or null to proceed without gym
|
||||
try {
|
||||
await fetch(`${API_BASE_URL}/api/users/gym`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({ gymId: selectedGymId }),
|
||||
});
|
||||
await gymsApi.updateUserGym(selectedGymId, token);
|
||||
} catch (e) {
|
||||
log.warn("Failed to update gym selection", { gymId: selectedGymId });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user