Relationship component really close to just working really well
This commit is contained in:
		
							
								
								
									
										57
									
								
								components/services/securestorage/RelationshipData.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								components/services/securestorage/RelationshipData.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
			
		||||
import * as SecureStore from 'expo-secure-store';
 | 
			
		||||
 | 
			
		||||
type UserData = {
 | 
			
		||||
  id: number;
 | 
			
		||||
  appleId: string | null;
 | 
			
		||||
  appleEmail: string | null;
 | 
			
		||||
  fullName: string;
 | 
			
		||||
  pfpURL: string | null;
 | 
			
		||||
  pushToken: string;
 | 
			
		||||
  createdAt: Date;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
type Relationship = {
 | 
			
		||||
  id: number;
 | 
			
		||||
  title: string;
 | 
			
		||||
  status: 'pending' | 'accepted' | 'rejected';
 | 
			
		||||
  relationshipStartDate: Date;
 | 
			
		||||
  createdAt: Date;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
type RelationshipData = {
 | 
			
		||||
  relationship: Relationship;
 | 
			
		||||
  partner: UserData;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const saveRelationshipData = async (RelationshipData: RelationshipData) => {
 | 
			
		||||
  try {
 | 
			
		||||
    await SecureStore.setItemAsync('RelationshipData', JSON.stringify(RelationshipData));
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.error('Error saving user data:', error);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const getRelationshipData = async () => {
 | 
			
		||||
  try { 
 | 
			
		||||
    const RelationshipData = await SecureStore.getItemAsync('RelationshipData');
 | 
			
		||||
    return RelationshipData ? JSON.parse(RelationshipData) : null;
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.error('Error getting user data:', error);
 | 
			
		||||
    return null;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const updateRelationshipData = async (updatedFields: Partial<any>) => {
 | 
			
		||||
  try {
 | 
			
		||||
    const currentUserData: RelationshipData = await getRelationshipData() as RelationshipData;
 | 
			
		||||
    if (currentUserData) {
 | 
			
		||||
      const updatedUserData: RelationshipData = { ...currentUserData, ...updatedFields };
 | 
			
		||||
      await saveRelationshipData(updatedUserData);
 | 
			
		||||
      return updatedUserData as RelationshipData;
 | 
			
		||||
    }
 | 
			
		||||
    return null;
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.error('Error updating user data:', error);
 | 
			
		||||
    return null;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
@@ -1,6 +1,16 @@
 | 
			
		||||
import * as SecureStore from 'expo-secure-store';
 | 
			
		||||
 | 
			
		||||
export const saveUserData = async (userData: any) => {
 | 
			
		||||
type UserData = {
 | 
			
		||||
  id: number;
 | 
			
		||||
  appleId: string | null;
 | 
			
		||||
  appleEmail: string | null;
 | 
			
		||||
  fullName: string;
 | 
			
		||||
  pfpURL: string | null;
 | 
			
		||||
  pushToken: string;
 | 
			
		||||
  createdAt: Date;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const saveUserData = async (userData: UserData) => {
 | 
			
		||||
  try {
 | 
			
		||||
    await SecureStore.setItemAsync('userData', JSON.stringify(userData));
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
@@ -20,11 +30,11 @@ export const getUserData = async () => {
 | 
			
		||||
 | 
			
		||||
export const updateUserData = async (updatedFields: Partial<any>) => {
 | 
			
		||||
  try {
 | 
			
		||||
    const currentUserData = await getUserData();
 | 
			
		||||
    const currentUserData: UserData = await getUserData() as UserData;
 | 
			
		||||
    if (currentUserData) {
 | 
			
		||||
      const updatedUserData = { ...currentUserData, ...updatedFields };
 | 
			
		||||
      const updatedUserData: UserData = { ...currentUserData, ...updatedFields };
 | 
			
		||||
      await saveUserData(updatedUserData);
 | 
			
		||||
      return updatedUserData;
 | 
			
		||||
      return updatedUserData as UserData;
 | 
			
		||||
    }
 | 
			
		||||
    return null;
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user