Compare commits

..
5 Commits
Author SHA1 Message Date
dimitar 5d1d881f16 db url fix in drizzle config 2025-11-23 17:32:01 +01:00
dimitar 1b50bfd2ee api calls simplified 2025-11-23 17:12:14 +01:00
dimitar 6cbed4e8d1 deps 2025-11-23 16:57:21 +01:00
dimitar 76dafe9cd5 fix deps 2025-11-23 16:39:02 +01:00
dimitar a96f1902c5 social login
implemented, we can add more providers later
2025-11-20 19:28:39 +01:00
17 changed files with 357 additions and 147 deletions

No files matched your search

Binary file not shown.
+3 -2
View File
@@ -27,8 +27,9 @@
"favicon": "./assets/favicon.png"
},
"plugins": [
"expo-router"
"expo-router",
"expo-font"
],
"scheme": "fitai"
}
}
}
+68 -73
View File
@@ -11,7 +11,7 @@
"@clerk/clerk-expo": "^2.18.3",
"@expo/vector-icons": "^15.0.0",
"@hookform/resolvers": "^3.3.0",
"@react-native-picker/picker": "^2.11.4",
"@react-native-picker/picker": "2.11.1",
"@tanstack/react-query": "^5.0.0",
"ajv": "^8.12.0",
"ajv-keywords": "^5.1.0",
@@ -21,6 +21,7 @@
"expo-camera": "~17.0.0",
"expo-constants": "^18.0.10",
"expo-crypto": "^15.0.7",
"expo-font": "~14.0.9",
"expo-linking": "~8.0.0",
"expo-notifications": "~0.32.0",
"expo-router": "~6.0.14",
@@ -28,7 +29,7 @@
"expo-status-bar": "^3.0.8",
"expo-web-browser": "^15.0.9",
"react": "19.1.0",
"react-dom": "^19.2.0",
"react-dom": "19.1.0",
"react-hook-form": "^7.47.0",
"react-native": "0.81.5",
"react-native-safe-area-context": "~5.6.0",
@@ -4029,9 +4030,9 @@
}
},
"node_modules/@react-native-picker/picker": {
"version": "2.11.4",
"resolved": "https://registry.npmjs.org/@react-native-picker/picker/-/picker-2.11.4.tgz",
"integrity": "sha512-Kf8h1AMnBo54b1fdiVylP2P/iFcZqzpMYcglC28EEFB1DEnOjsNr6Ucqc+3R9e91vHxEDnhZFbYDmAe79P2gjA==",
"version": "2.11.1",
"resolved": "https://registry.npmjs.org/@react-native-picker/picker/-/picker-2.11.1.tgz",
"integrity": "sha512-ThklnkK4fV3yynnIIRBkxxjxR4IFbdMNJVF6tlLdOJ/zEFUEFUEdXY0KmH0iYzMwY8W4/InWsLiA7AkpAbnexA==",
"license": "MIT",
"workspaces": [
"example"
@@ -6946,9 +6947,9 @@
}
},
"node_modules/expo": {
"version": "54.0.23",
"resolved": "https://registry.npmjs.org/expo/-/expo-54.0.23.tgz",
"integrity": "sha512-b4uQoiRwQ6nwqsT2709RS15CWYNGF3eJtyr1KyLw9WuMAK7u4jjofkhRiO0+3o1C2NbV+WooyYTOZGubQQMBaQ==",
"version": "54.0.25",
"resolved": "https://registry.npmjs.org/expo/-/expo-54.0.25.tgz",
"integrity": "sha512-+iSeBJfHRHzNPnHMZceEXhSGw4t5bNqFyd/5xMUoGfM+39rO7F72wxiLRpBKj0M6+0GQtMaEs+eTbcCrO7XyJQ==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.20.0",
@@ -6962,13 +6963,13 @@
"@expo/vector-icons": "^15.0.3",
"@ungap/structured-clone": "^1.3.0",
"babel-preset-expo": "~54.0.7",
"expo-asset": "~12.0.9",
"expo-asset": "~12.0.10",
"expo-constants": "~18.0.10",
"expo-file-system": "~19.0.17",
"expo-file-system": "~19.0.19",
"expo-font": "~14.0.9",
"expo-keep-awake": "~15.0.7",
"expo-modules-autolinking": "3.0.21",
"expo-modules-core": "3.0.25",
"expo-modules-autolinking": "3.0.22",
"expo-modules-core": "3.0.26",
"pretty-format": "^29.7.0",
"react-refresh": "^0.14.2",
"whatwg-url-without-unicode": "8.0.0-3"
@@ -7006,17 +7007,32 @@
"expo": "*"
}
},
"node_modules/expo-asset": {
"version": "12.0.10",
"resolved": "https://registry.npmjs.org/expo-asset/-/expo-asset-12.0.10.tgz",
"integrity": "sha512-pZyeJkoDsALh4gpCQDzTA/UCLaPH/1rjQNGubmLn/uDM27S4iYJb/YWw4+CNZOtd5bCUOhDPg5DtGQnydNFSXg==",
"license": "MIT",
"dependencies": {
"@expo/image-utils": "^0.8.7",
"expo-constants": "~18.0.10"
},
"peerDependencies": {
"expo": "*",
"react": "*",
"react-native": "*"
}
},
"node_modules/expo-auth-session": {
"version": "7.0.8",
"resolved": "https://registry.npmjs.org/expo-auth-session/-/expo-auth-session-7.0.8.tgz",
"integrity": "sha512-kpo2Jva+6uVjk6TmNqWAoqTnULXZaEVa9l4uf8JH32uDMt/iZQhM0fauy7Ww+y910Euhv5djCP7cPj8KWv6cmQ==",
"version": "7.0.9",
"resolved": "https://registry.npmjs.org/expo-auth-session/-/expo-auth-session-7.0.9.tgz",
"integrity": "sha512-mPSwaRWOJYas160lXi5P/7BkLy0xbh+er+IMmAYHqf2+iz2WWs9W/4lMAklQVJG2mCyOZi24XrkffvB2izCa1g==",
"license": "MIT",
"dependencies": {
"expo-application": "~7.0.7",
"expo-constants": "~18.0.8",
"expo-constants": "~18.0.10",
"expo-crypto": "~15.0.7",
"expo-linking": "~8.0.8",
"expo-web-browser": "~15.0.7",
"expo-linking": "~8.0.9",
"expo-web-browser": "~15.0.9",
"invariant": "^2.2.4"
},
"peerDependencies": {
@@ -7070,6 +7086,16 @@
"expo": "*"
}
},
"node_modules/expo-file-system": {
"version": "19.0.19",
"resolved": "https://registry.npmjs.org/expo-file-system/-/expo-file-system-19.0.19.tgz",
"integrity": "sha512-OrpOV4fEBFMFv+jy7PnENpPbsWoBmqWGidSwh1Ai52PLl6JIInYGfZTc6kqyPNGtFTwm7Y9mSWnE8g+dtLxu7g==",
"license": "MIT",
"peerDependencies": {
"expo": "*",
"react-native": "*"
}
},
"node_modules/expo-font": {
"version": "14.0.9",
"resolved": "https://registry.npmjs.org/expo-font/-/expo-font-14.0.9.tgz",
@@ -7085,12 +7111,12 @@
}
},
"node_modules/expo-linking": {
"version": "8.0.8",
"resolved": "https://registry.npmjs.org/expo-linking/-/expo-linking-8.0.8.tgz",
"integrity": "sha512-MyeMcbFDKhXh4sDD1EHwd0uxFQNAc6VCrwBkNvvvufUsTYFq3glTA9Y8a+x78CPpjNqwNAamu74yIaIz7IEJyg==",
"version": "8.0.9",
"resolved": "https://registry.npmjs.org/expo-linking/-/expo-linking-8.0.9.tgz",
"integrity": "sha512-a0UHhlVyfwIbn8b1PSFPoFiIDJeps2iEq109hVH3CHd0CMKuRxFfNio9Axe2BjXhiJCYWR4OV1iIyzY/GjiVkQ==",
"license": "MIT",
"dependencies": {
"expo-constants": "~18.0.8",
"expo-constants": "~18.0.10",
"invariant": "^2.2.4"
},
"peerDependencies": {
@@ -7099,9 +7125,9 @@
}
},
"node_modules/expo-modules-autolinking": {
"version": "3.0.21",
"resolved": "https://registry.npmjs.org/expo-modules-autolinking/-/expo-modules-autolinking-3.0.21.tgz",
"integrity": "sha512-pOtPDLln3Ju8DW1zRW4OwZ702YqZ8g+kM/tEY1sWfv22kWUtxkvK+ytRDRpRdnKEnC28okbhWqeMnmVkSFzP6Q==",
"version": "3.0.22",
"resolved": "https://registry.npmjs.org/expo-modules-autolinking/-/expo-modules-autolinking-3.0.22.tgz",
"integrity": "sha512-Ej4SsZAnUUVFmbn6SoBso8K308mRKg8xgapdhP7v7IaSgfbexUoqxoiV31949HQQXuzmgvpkXCfp6Ex+mDW0EQ==",
"license": "MIT",
"dependencies": {
"@expo/spawn-async": "^1.7.2",
@@ -7115,9 +7141,9 @@
}
},
"node_modules/expo-modules-core": {
"version": "3.0.25",
"resolved": "https://registry.npmjs.org/expo-modules-core/-/expo-modules-core-3.0.25.tgz",
"integrity": "sha512-0P8PT8UV6c5/+p8zeVM/FXvBgn/ErtGcMaasqUgbzzBUg94ktbkIrij9t9reGCrir03BYt/Bcpv+EQtYC8JOug==",
"version": "3.0.26",
"resolved": "https://registry.npmjs.org/expo-modules-core/-/expo-modules-core-3.0.26.tgz",
"integrity": "sha512-WWjficXz32VmQ+xDoO+c0+jwDME0n/47wONrJkRvtm32H9W8n3MXkOMGemDl95HyPKYsaYKhjFGUOVOxIF3hcQ==",
"license": "MIT",
"dependencies": {
"invariant": "^2.2.4"
@@ -7128,9 +7154,9 @@
}
},
"node_modules/expo-notifications": {
"version": "0.32.12",
"resolved": "https://registry.npmjs.org/expo-notifications/-/expo-notifications-0.32.12.tgz",
"integrity": "sha512-FVJ5W4rOpKvmrLJ1Sd5pxiVTV4a7ApgTlKro+E5X8M2TBbXmEVOjs09klzdalXTjlzmU/Gu8aRw9xr7Ea/gZdw==",
"version": "0.32.13",
"resolved": "https://registry.npmjs.org/expo-notifications/-/expo-notifications-0.32.13.tgz",
"integrity": "sha512-PL0R1ulLVUgAswlXtRDKxBlcipNM3YA6+P5nB5JIhXbsjLJ7y+EKVaEhHhbaGzuK1QVsRQSJNm/4oISX+vsmFQ==",
"license": "MIT",
"dependencies": {
"@expo/image-utils": "^0.8.7",
@@ -7139,7 +7165,7 @@
"assert": "^2.0.0",
"badgin": "^1.1.5",
"expo-application": "~7.0.7",
"expo-constants": "~18.0.9"
"expo-constants": "~18.0.10"
},
"peerDependencies": {
"expo": "*",
@@ -7148,9 +7174,9 @@
}
},
"node_modules/expo-router": {
"version": "6.0.14",
"resolved": "https://registry.npmjs.org/expo-router/-/expo-router-6.0.14.tgz",
"integrity": "sha512-vizLO4SgnMEL+PPs2dXr+etEOuksjue7yUQBCtfCEdqoDkQlB0r35zI7rS34Wt53sxKWSlM2p+038qQEpxtiFw==",
"version": "6.0.15",
"resolved": "https://registry.npmjs.org/expo-router/-/expo-router-6.0.15.tgz",
"integrity": "sha512-PAettvLifQzb6hibCmBqxbR9UljlH61GvDRLyarGxs/tG9OpMXCoZHZo8gGCO24K1/6cchBKBcjvQ0PRrKwPew==",
"license": "MIT",
"dependencies": {
"@expo/metro-runtime": "^6.1.2",
@@ -7163,7 +7189,7 @@
"client-only": "^0.0.1",
"debug": "^4.3.4",
"escape-string-regexp": "^4.0.0",
"expo-server": "^1.0.3",
"expo-server": "^1.0.4",
"fast-deep-equal": "^3.1.3",
"invariant": "^2.2.4",
"nanoid": "^3.3.8",
@@ -7183,7 +7209,7 @@
"@testing-library/react-native": ">= 12.0.0",
"expo": "*",
"expo-constants": "^18.0.10",
"expo-linking": "^8.0.8",
"expo-linking": "^8.0.9",
"react": "*",
"react-dom": "*",
"react-native": "*",
@@ -7271,31 +7297,6 @@
"react-native": "*"
}
},
"node_modules/expo/node_modules/expo-asset": {
"version": "12.0.9",
"resolved": "https://registry.npmjs.org/expo-asset/-/expo-asset-12.0.9.tgz",
"integrity": "sha512-vrdRoyhGhBmd0nJcssTSk1Ypx3Mbn/eXaaBCQVkL0MJ8IOZpAObAjfD5CTy8+8RofcHEQdh3wwZVCs7crvfOeg==",
"license": "MIT",
"dependencies": {
"@expo/image-utils": "^0.8.7",
"expo-constants": "~18.0.9"
},
"peerDependencies": {
"expo": "*",
"react": "*",
"react-native": "*"
}
},
"node_modules/expo/node_modules/expo-file-system": {
"version": "19.0.17",
"resolved": "https://registry.npmjs.org/expo-file-system/-/expo-file-system-19.0.17.tgz",
"integrity": "sha512-WwaS01SUFrxBnExn87pg0sCTJjZpf2KAOzfImG0o8yhkU7fbYpihpl/oocXBEsNbj58a8hVt1Y4CVV5c1tzu/g==",
"license": "MIT",
"peerDependencies": {
"expo": "*",
"react-native": "*"
}
},
"node_modules/expo/node_modules/expo-keep-awake": {
"version": "15.0.7",
"resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-15.0.7.tgz",
@@ -11316,23 +11317,17 @@
}
},
"node_modules/react-dom": {
"version": "19.2.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.0.tgz",
"integrity": "sha512-UlbRu4cAiGaIewkPyiRGJk0imDN2T3JjieT6spoL2UeSf5od4n5LB/mQ4ejmxhCFT1tYe8IvaFulzynWovsEFQ==",
"version": "19.1.0",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.1.0.tgz",
"integrity": "sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g==",
"license": "MIT",
"dependencies": {
"scheduler": "^0.27.0"
"scheduler": "^0.26.0"
},
"peerDependencies": {
"react": "^19.2.0"
"react": "^19.1.0"
}
},
"node_modules/react-dom/node_modules/scheduler": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz",
"integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==",
"license": "MIT"
},
"node_modules/react-fast-compare": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-3.2.2.tgz",
+3 -2
View File
@@ -17,7 +17,7 @@
"@clerk/clerk-expo": "^2.18.3",
"@expo/vector-icons": "^15.0.0",
"@hookform/resolvers": "^3.3.0",
"@react-native-picker/picker": "^2.11.4",
"@react-native-picker/picker": "2.11.1",
"@tanstack/react-query": "^5.0.0",
"ajv": "^8.12.0",
"ajv-keywords": "^5.1.0",
@@ -27,6 +27,7 @@
"expo-camera": "~17.0.0",
"expo-constants": "^18.0.10",
"expo-crypto": "^15.0.7",
"expo-font": "~14.0.9",
"expo-linking": "~8.0.0",
"expo-notifications": "~0.32.0",
"expo-router": "~6.0.14",
@@ -34,7 +35,7 @@
"expo-status-bar": "^3.0.8",
"expo-web-browser": "^15.0.9",
"react": "19.1.0",
"react-dom": "^19.2.0",
"react-dom": "19.1.0",
"react-hook-form": "^7.47.0",
"react-native": "0.81.5",
"react-native-safe-area-context": "~5.6.0",
+47
View File
@@ -0,0 +1,47 @@
import { apiClient } from "./client";
import { API_ENDPOINTS } from "../config/api";
export interface Attendance {
id: string;
checkInTime: string;
checkOutTime?: string;
type: string;
notes?: string;
}
export const attendanceApi = {
getHistory: async (token: string): Promise<Attendance[]> => {
try {
const response = await apiClient.get(API_ENDPOINTS.ATTENDANCE.HISTORY, {
headers: { Authorization: `Bearer ${token}` },
});
return response.data;
} catch (error) {
throw error;
}
},
checkIn: async (type: string, token: string): Promise<void> => {
try {
await apiClient.post(
API_ENDPOINTS.ATTENDANCE.CHECK_IN,
{ type },
{ headers: { Authorization: `Bearer ${token}` } },
);
} catch (error) {
throw error;
}
},
checkOut: async (token: string): Promise<void> => {
try {
await apiClient.post(
API_ENDPOINTS.ATTENDANCE.CHECK_OUT,
{},
{ headers: { Authorization: `Bearer ${token}` } },
);
} catch (error) {
throw error;
}
},
};
+18
View File
@@ -0,0 +1,18 @@
import axios from 'axios';
import { API_BASE_URL } from '../config/api';
export const apiClient = axios.create({
baseURL: API_BASE_URL,
headers: {
'Content-Type': 'application/json',
},
});
// Helper to set the auth token for a request
export const setAuthToken = (token: string) => {
if (token) {
apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
} else {
delete apiClient.defaults.headers.common['Authorization'];
}
};
+9 -9
View File
@@ -1,5 +1,5 @@
import axios from "axios";
import { API_BASE_URL } from "../config/api";
import { apiClient } from "./client";
import { API_ENDPOINTS } from "../config/api";
export interface FitnessProfile {
id?: string;
@@ -22,10 +22,10 @@ export const fitnessProfileApi = {
try {
console.log(
"Getting fitness profile with URL:",
`${API_BASE_URL}/api/users/${userId}/fitness-profile`,
`${API_ENDPOINTS.USERS}/${userId}/fitness-profile`,
);
const response = await axios.get(
`${API_BASE_URL}/api/users/${userId}/fitness-profile`,
const response = await apiClient.get(
`${API_ENDPOINTS.USERS}/${userId}/fitness-profile`,
{
headers: {
Authorization: `Bearer ${token}`,
@@ -49,8 +49,8 @@ export const fitnessProfileApi = {
token: string,
): Promise<FitnessProfile> => {
try {
const response = await axios.put(
`${API_BASE_URL}/api/users/${userId}/fitness-profile`,
const response = await apiClient.put(
`${API_ENDPOINTS.USERS}/${userId}/fitness-profile`,
data,
{
headers: {
@@ -74,8 +74,8 @@ export const fitnessProfileApi = {
token: string,
): Promise<FitnessProfile> => {
try {
const response = await axios.post(
`${API_BASE_URL}/api/users/${data.clientId}/fitness-profile`,
const response = await apiClient.post(
`${API_ENDPOINTS.USERS}/${data.clientId}/fitness-profile`,
data,
{
headers: {
+30
View File
@@ -0,0 +1,30 @@
import { apiClient } from "./client";
import { API_ENDPOINTS } from "../config/api";
export interface FitnessProfileData {
userId: string;
height: string;
weight: string;
age: string;
gender: "male" | "female" | "other";
activityLevel: "sedentary" | "light" | "moderate" | "active" | "very_active";
fitnessGoals: string[];
exerciseHabits: string;
dietHabits: string;
medicalConditions: string;
}
export const profileApi = {
createFitnessProfile: async (
data: FitnessProfileData,
token: string,
): Promise<void> => {
try {
await apiClient.post(API_ENDPOINTS.PROFILE.FITNESS, data, {
headers: { Authorization: `Bearer ${token}` },
});
} catch (error) {
throw error;
}
},
};
+31 -7
View File
@@ -1,4 +1,4 @@
import React from "react";
import { useState, useEffect } from "react";
import { useSignIn, useAuth } from "@clerk/clerk-expo";
import { useRouter } from "expo-router";
import {
@@ -12,19 +12,20 @@ import {
Platform,
ScrollView,
} from "react-native";
import { OAuthButtons } from "../../components/auth/OAuthButtons";
export default function SignInScreen() {
const { signIn, setActive, isLoaded } = useSignIn();
const { isSignedIn } = useAuth();
const router = useRouter();
const [emailAddress, setEmailAddress] = React.useState("");
const [password, setPassword] = React.useState("");
const [loading, setLoading] = React.useState(false);
const [error, setError] = React.useState("");
const [emailAddress, setEmailAddress] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
// Redirect if already signed in
React.useEffect(() => {
useEffect(() => {
if (isSignedIn) {
router.replace("/(tabs)");
}
@@ -64,7 +65,7 @@ export default function SignInScreen() {
setError(
err.errors?.[0]?.message ||
"Failed to sign in. Please check your credentials.",
"Failed to sign in. Please check your credentials.",
);
} finally {
setLoading(false);
@@ -100,6 +101,14 @@ export default function SignInScreen() {
</View>
) : null}
<OAuthButtons />
<View style={styles.dividerContainer}>
<View style={styles.dividerLine} />
<Text style={styles.dividerText}>OR</Text>
<View style={styles.dividerLine} />
</View>
<View style={styles.form}>
<View style={styles.inputContainer}>
<Text style={styles.label}>Email</Text>
@@ -256,4 +265,19 @@ const styles = StyleSheet.create({
color: "#2563eb",
fontWeight: "600",
},
dividerContainer: {
flexDirection: "row",
alignItems: "center",
marginBottom: 24,
},
dividerLine: {
flex: 1,
height: 1,
backgroundColor: "#ddd",
},
dividerText: {
marginHorizontal: 10,
color: "#666",
fontSize: 14,
},
});
+34 -10
View File
@@ -1,4 +1,4 @@
import React from "react";
import { useState, useEffect } from "react";
import { useSignUp, useAuth } from "@clerk/clerk-expo";
import { useRouter } from "expo-router";
import {
@@ -12,23 +12,24 @@ import {
Platform,
ScrollView,
} from "react-native";
import { OAuthButtons } from "../../components/auth/OAuthButtons";
export default function SignUpScreen() {
const { signUp, setActive, isLoaded } = useSignUp();
const { isSignedIn } = useAuth();
const router = useRouter();
const [emailAddress, setEmailAddress] = React.useState("");
const [password, setPassword] = React.useState("");
const [firstName, setFirstName] = React.useState("");
const [lastName, setLastName] = React.useState("");
const [pendingVerification, setPendingVerification] = React.useState(false);
const [code, setCode] = React.useState("");
const [loading, setLoading] = React.useState(false);
const [error, setError] = React.useState("");
const [emailAddress, setEmailAddress] = useState("");
const [password, setPassword] = useState("");
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [pendingVerification, setPendingVerification] = useState(false);
const [code, setCode] = useState("");
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
// Redirect if already signed in
React.useEffect(() => {
useEffect(() => {
if (isSignedIn) {
router.replace("/(tabs)");
}
@@ -182,6 +183,14 @@ export default function SignUpScreen() {
</View>
) : null}
<OAuthButtons />
<View style={styles.dividerContainer}>
<View style={styles.dividerLine} />
<Text style={styles.dividerText}>OR</Text>
<View style={styles.dividerLine} />
</View>
<View style={styles.form}>
<View style={styles.inputContainer}>
<Text style={styles.label}>First Name</Text>
@@ -372,4 +381,19 @@ const styles = StyleSheet.create({
color: "#2563eb",
fontWeight: "600",
},
dividerContainer: {
flexDirection: "row",
alignItems: "center",
marginBottom: 24,
},
dividerLine: {
flex: 1,
height: 1,
backgroundColor: "#ddd",
},
dividerText: {
marginHorizontal: 10,
color: "#666",
fontSize: 14,
},
});
+11 -25
View File
@@ -1,16 +1,9 @@
import { View, Text, StyleSheet, TouchableOpacity, ActivityIndicator, ScrollView, Alert } from 'react-native'
import { useState, useEffect } from 'react'
import { useAuth } from '@clerk/clerk-expo'
import axios from 'axios'
import { API_BASE_URL, API_ENDPOINTS } from '../../config/api'
import { attendanceApi, Attendance } from '../../api/attendance'
interface Attendance {
id: string
checkInTime: string
checkOutTime?: string
type: string
notes?: string
}
export default function AttendanceScreen() {
const { getToken, userId } = useAuth()
@@ -22,13 +15,10 @@ export default function AttendanceScreen() {
try {
setLoading(true)
const token = await getToken()
const url = `${API_BASE_URL}${API_ENDPOINTS.ATTENDANCE.HISTORY}`
console.log('Fetching attendance from:', url)
const response = await axios.get(url, {
headers: { Authorization: `Bearer ${token}` }
})
if (!token) return
const data: Attendance[] = response.data
console.log('Fetching attendance history')
const data = await attendanceApi.getHistory(token)
setHistory(data)
// Check if there's an active check-in (latest one has no checkOutTime)
@@ -52,11 +42,9 @@ export default function AttendanceScreen() {
const handleCheckIn = async () => {
try {
const token = await getToken()
await axios.post(
`${API_BASE_URL}${API_ENDPOINTS.ATTENDANCE.CHECK_IN}`,
{ type: 'gym' },
{ headers: { Authorization: `Bearer ${token}` } }
)
if (!token) return
await attendanceApi.checkIn('gym', token)
fetchAttendance()
Alert.alert('Success', 'Checked in successfully!')
} catch (error: any) {
@@ -68,11 +56,9 @@ export default function AttendanceScreen() {
const handleCheckOut = async () => {
try {
const token = await getToken()
await axios.post(
`${API_BASE_URL}${API_ENDPOINTS.ATTENDANCE.CHECK_OUT}`,
{},
{ headers: { Authorization: `Bearer ${token}` } }
)
if (!token) return
await attendanceApi.checkOut(token)
fetchAttendance()
Alert.alert('Success', 'Checked out successfully!')
} catch (error: any) {
+21 -15
View File
@@ -1,9 +1,9 @@
import React, { useState } from 'react'
import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, ScrollView } from 'react-native'
import { useRouter } from 'expo-router'
import axios from 'axios'
import { useAuth } from '@clerk/clerk-expo'
import * as SecureStore from 'expo-secure-store'
import { API_BASE_URL, API_ENDPOINTS } from '../config/api'
import { profileApi } from '../api/profile'
interface FitnessProfile {
height: string
@@ -31,10 +31,11 @@ export default function WelcomeScreen() {
})
const [loading, setLoading] = useState(false)
const router = useRouter()
const { getToken } = useAuth()
const fitnessGoalsOptions = [
'Weight Loss',
'Muscle Gain',
'Muscle Gain',
'Improve Endurance',
'Better Flexibility',
'General Fitness',
@@ -67,26 +68,31 @@ export default function WelcomeScreen() {
setLoading(true)
try {
const token = await getToken()
if (!token) {
throw new Error('Authentication required')
}
const user = await SecureStore.getItemAsync('user')
if (!user) {
throw new Error('No user found')
}
const userData = JSON.parse(user)
const response = await axios.post(
`${API_BASE_URL}${API_ENDPOINTS.PROFILE.FITNESS}`,
await profileApi.createFitnessProfile(
{
userId: userData.id,
...profile
}
},
token
)
if (response.status === 201) {
Alert.alert('Success', 'Profile completed successfully!', [
{ text: 'OK', onPress: () => router.replace('/(tabs)') }
])
}
Alert.alert('Success', 'Profile completed successfully!', [
{ text: 'OK', onPress: () => router.replace('/(tabs)') }
])
} catch (error: any) {
console.log('Profile save error:', error)
Alert.alert('Error', error.response?.data?.error || 'Failed to save profile. Please try again.')
@@ -103,7 +109,7 @@ export default function WelcomeScreen() {
<View style={styles.section}>
<Text style={styles.sectionTitle}>Basic Information</Text>
<View style={styles.row}>
<View style={[styles.inputContainer, { flex: 1, marginRight: 8 }]}>
<Text style={styles.label}>Height (cm)</Text>
@@ -115,7 +121,7 @@ export default function WelcomeScreen() {
placeholder="170"
/>
</View>
<View style={[styles.inputContainer, { flex: 1, marginLeft: 8 }]}>
<Text style={styles.label}>Weight (kg)</Text>
<TextInput
@@ -139,7 +145,7 @@ export default function WelcomeScreen() {
placeholder="25"
/>
</View>
<View style={[styles.inputContainer, { flex: 1, marginLeft: 8 }]}>
<Text style={styles.label}>Gender</Text>
<View style={styles.genderRow}>
@@ -0,0 +1,64 @@
import React from "react";
import * as WebBrowser from "expo-web-browser";
import { Button, View, StyleSheet, TouchableOpacity, Text } from "react-native";
import { useOAuth } from "@clerk/clerk-expo";
import { useWarmUpBrowser } from "../../hooks/useWarmUpBrowser";
import { Ionicons } from "@expo/vector-icons";
WebBrowser.maybeCompleteAuthSession();
export function OAuthButtons() {
useWarmUpBrowser();
const { startOAuthFlow } = useOAuth({ strategy: "oauth_google" });
const onPress = React.useCallback(async () => {
try {
const { createdSessionId, signIn, signUp, setActive } =
await startOAuthFlow();
if (createdSessionId) {
setActive!({ session: createdSessionId });
} else {
// Use signIn or signUp for next steps such as MFA
}
} catch (err) {
console.error("OAuth error", err);
}
}, []);
return (
<View style={styles.container}>
<TouchableOpacity style={styles.button} onPress={onPress}>
<Ionicons name="logo-google" size={20} color="#DB4437" style={styles.icon} />
<Text style={styles.text}>Continue with Google</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
width: "100%",
marginTop: 16,
},
button: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
backgroundColor: "#fff",
borderWidth: 1,
borderColor: "#ddd",
paddingVertical: 12,
borderRadius: 8,
marginBottom: 12,
},
icon: {
marginRight: 10,
},
text: {
fontSize: 16,
fontWeight: "500",
color: "#333",
},
});
+2 -2
View File
@@ -1,5 +1,5 @@
export const API_BASE_URL = __DEV__
? 'https://390dfd6ece05.ngrok-free.app'
? 'https://f0a9b87c3831.ngrok-free.app'
: 'https://your-production-url.com'
export const API_ENDPOINTS = {
@@ -18,4 +18,4 @@ export const API_ENDPOINTS = {
HISTORY: '/api/attendance/history',
},
RECOMMENDATIONS: '/api/recommendations',
}
}
+13
View File
@@ -0,0 +1,13 @@
import React from "react";
import * as WebBrowser from "expo-web-browser";
export const useWarmUpBrowser = () => {
React.useEffect(() => {
// Warm up the android browser to improve UX
// https://docs.expo.dev/guides/authentication/#improving-user-experience
void WebBrowser.warmUpAsync();
return () => {
void WebBrowser.coolDownAsync();
};
}, []);
};
+2 -1
View File
@@ -5,6 +5,7 @@ export default defineConfig({
out: "./drizzle",
dialect: "sqlite",
dbCredentials: {
url: "./fitai.db",
// url: "./fitai.db",
url: "../../apps/admin/data/fitai.db",
},
});
+1 -1
View File
@@ -1,5 +1,5 @@
## TODOS
- fix fitness-profile network error
<!-- - fix fitness-profile network error -->
- enhance mobile up ui and styling
- implement create admin/trainer/client flow