summaryrefslogtreecommitdiffstats
path: root/src/features/profile/services
diff options
context:
space:
mode:
authorAlberto Duarte Delgado <alberto@albertoduarte.com>2026-04-19 21:46:46 +0100
committerAlberto Duarte Delgado <alberto@albertoduarte.com>2026-04-19 21:46:46 +0100
commitbe90a5f202f80bb423c6e0aaf1c4d5feca668f01 (patch)
treec91081a6c60d2f1efb4de22c324721c5d798e3ee /src/features/profile/services
parent40cc6cea25d048c2e77e11bbfea0cd1e5eb784f6 (diff)
parent4d0962a44715f71acd2fc9ea59bf87d8da70f662 (diff)
Merge branch 'feature/anita' into develop
Diffstat (limited to 'src/features/profile/services')
-rw-r--r--src/features/profile/services/profileService.ts67
1 files changed, 53 insertions, 14 deletions
diff --git a/src/features/profile/services/profileService.ts b/src/features/profile/services/profileService.ts
index f7e89b4..c202c18 100644
--- a/src/features/profile/services/profileService.ts
+++ b/src/features/profile/services/profileService.ts
@@ -1,13 +1,21 @@
// src/features/profile/services/profileService.ts
-import { doc, getDoc, setDoc } from 'firebase/firestore';
-import { updateProfile } from 'firebase/auth';
-import { db, auth } from '@/shared/lib/firebase/config';
-import { UserProfile } from '@/features/profile/types';
+import { UserProfile } from "@/features/profile/types";
+import { auth, db } from "@/shared/lib/firebase/config";
+import { mockDelay, mockUserProfile } from "@/shared/lib/mockData";
+import { updateProfile } from "firebase/auth";
+import { doc, getDoc, setDoc } from "firebase/firestore";
+
+const USE_MOCK = process.env.EXPO_PUBLIC_USE_MOCK_DATA === "true";
export const profileService = {
async getMyProfile(uid: string): Promise<UserProfile | null> {
- const snapshot = await getDoc(doc(db, 'users', uid));
+ if (USE_MOCK) {
+ await mockDelay();
+ return mockUserProfile.uid === uid ? mockUserProfile : null;
+ }
+
+ const snapshot = await getDoc(doc(db, "users", uid));
if (!snapshot.exists()) {
return null;
@@ -17,9 +25,12 @@ export const profileService = {
return {
uid,
- email: data.email ?? '',
- displayName: data.displayName ?? '',
- photoURL: data.photoURL ?? '',
+ email: data.email ?? "",
+ displayName: data.displayName ?? "",
+ photoURL: data.photoURL ?? "",
+ phone: data.phone ?? "",
+ company: data.company ?? "",
+ bio: data.bio ?? "",
};
},
@@ -27,15 +38,43 @@ export const profileService = {
uid: string;
displayName: string;
photoURL?: string;
+ phone?: string;
+ company?: string;
+ bio?: string;
}): Promise<void> {
- const { uid, displayName, photoURL } = params;
+ if (USE_MOCK) {
+ await mockDelay();
+ mockUserProfile.displayName = params.displayName;
+ if (params.photoURL !== undefined) {
+ mockUserProfile.photoURL = params.photoURL;
+ }
+ if (params.phone !== undefined) {
+ mockUserProfile.phone = params.phone;
+ }
+ if (params.company !== undefined) {
+ mockUserProfile.company = params.company;
+ }
+ if (params.bio !== undefined) {
+ mockUserProfile.bio = params.bio;
+ }
+ return;
+ }
+
+ const { uid, displayName, photoURL, phone, company, bio } = params;
const currentUser = auth.currentUser;
- await setDoc(doc(db, 'users', uid), {
- email: currentUser?.email ?? '',
- displayName,
- ...(photoURL !== undefined ? { photoURL } : {}),
- }, { merge: true });
+ await setDoc(
+ doc(db, "users", uid),
+ {
+ email: currentUser?.email ?? "",
+ displayName,
+ ...(photoURL !== undefined ? { photoURL } : {}),
+ ...(phone !== undefined ? { phone } : {}),
+ ...(company !== undefined ? { company } : {}),
+ ...(bio !== undefined ? { bio } : {}),
+ },
+ { merge: true },
+ );
if (currentUser) {
await updateProfile(currentUser, {