-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dafae19
commit c85752a
Showing
14 changed files
with
264 additions
and
93 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useState } from 'react'; | ||
import { User } from 'firebase/auth'; | ||
import { UserDataContext } from './userData.context'; | ||
import { UserData } from 'types/userData'; | ||
import { getUserData } from 'services/firebase'; | ||
|
||
const initialData: UserData = { | ||
id: '1', | ||
fullName: 'John Doe', | ||
gender: 'male', | ||
email: '[email protected]', | ||
phoneNumber: '12345', | ||
address: 'USA', | ||
bio: '', | ||
photoUrl: '', | ||
}; | ||
|
||
export const UserDataProvider: React.FC = ({ children }) => { | ||
const [userData, setUserData] = useState<UserData>(initialData); | ||
|
||
const fetchUserData = async (currentUser: User | null) => { | ||
try { | ||
const data = await getUserData(currentUser); | ||
|
||
if (!data) return; | ||
|
||
setUserData(data); | ||
} catch (error) { | ||
console.log(error); | ||
throw new Error('Oops! Something went wrong.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<UserDataContext.Provider | ||
value={{ userData, fetchUserData }} | ||
> | ||
{children} | ||
</UserDataContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './UserDataProvider'; | ||
export * from './userData.context'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createContext } from 'react'; | ||
import { User } from 'firebase/auth'; | ||
import { UserData } from 'types/userData'; | ||
|
||
const initialData: UserData = { | ||
id: '1', | ||
fullName: 'John Doe', | ||
gender: 'male', | ||
email: '[email protected]', | ||
phoneNumber: '12345', | ||
address: 'USA', | ||
bio: '', | ||
photoUrl: '', | ||
}; | ||
|
||
interface Context { | ||
userData: UserData; | ||
fetchUserData: (currentUser: User | null) => void; | ||
} | ||
|
||
export const UserDataContext = createContext<Context>({ | ||
userData: initialData, | ||
fetchUserData: () => { }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.