-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataStorage.js
101 lines (85 loc) · 2.64 KB
/
DataStorage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import * as firebase from 'firebase';
import { SecureStore } from 'expo';
class DataStorage {
static EMAIL;
static FULL_NAME;
static PHONE_NUM;
static IS_LAWYER;
// Laywer specific information
static EXP;
static DEGREE;
static SPECIALTY;
// Client specific information
static LOCATION;
static async saveLogin(email, password) {
console.log('Trying to save login....');
let savableEmail = email.substring(0, email.indexOf('@')) + '-at_' + email.substring(email.indexOf('@') + 1, email.length);
// Save email for login
SecureStore.setItemAsync('lastUser', savableEmail)
.then(() => {
// Save password
SecureStore.setItemAsync('password', password)
.then(() => {
console.log('Successfully saved email and pass');
})
.catch((error) => {
alert('Expo Error: ' + error.message);
})
})
.catch((error) => {
alert('Expo Error: ' + error.message);
})
}
static loadBasicData() {
const uid = firebase.auth().currentUser.uid;
firebase.database().ref('lawyerProfile/' + uid).once('value')
.then((snap) => {
// this.EMAIL = snap.val().email;
// this.IS_LAWYER = snap.val().isLawyer;
// this.FULL_NAME = snap.val().fullName;
// this.PHONE_NUM = snap.val().phoneNumber;
// console.log(this.EMAIL, this.IS_LAWYER, this.FULL_NAME, this.PHONE_NUM);
})
.catch((error) => {
alert('ERROR loading user data: ' + error.message);
})
}
static loadProfileData() {
const uid = firebase.auth().currentUser.uid;
// Load lawyer data
if (this.IS_LAWYER) {
firebase.database().ref('lawyerProfiles' + uid).once('value')
.then((snap) => {
// this.EXP = snap.val().experience;
// this.DEGREE = snap.val().degree;
// this.SPECIALTY = snap.val().specialty;
// console.log(this.EXP, this.DEGREE, this.SPECIALTY);
})
.catch((error) => {
alert('Cannot get lawyer data ' + error.message);
})
} else {
// Load client data
// firebase.database().ref('cases/' + uid).once('value')
// .then((snap) => {
// this.LOCATION = snap.val().location;
//
// console.log(this.LOCATION);
// })
// .catch((error) => {
// alert('Cannot get lawyer data ' + error.message);
// })
}
}
static clearData() {
this.EMAIL = '';
this.FULL_NAME = '';
this.PHONE_NUM = '';
this.IS_LAWYER = '';
this.EXP = '';
this.DEGREE = '';
this.SPECIALTY = '';
this.LOCATION = '';
}
}
export default DataStorage;