forked from Lemoncode/beer-geek-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/Lemoncode#27-crear-github-ci-configuracion-basi…
…ca' of https://github.com/torresgol10/beer-geek-menu into feature/Lemoncode#27-crear-github-ci-configuracion-basica
- Loading branch information
Showing
7 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
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 @@ | ||
export * from './sign-up'; |
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 './sign-up.context'; | ||
export * from './sign-up.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,4 @@ | ||
import React from 'react'; | ||
import { SignUpContextModel } from './sign-up.model'; | ||
|
||
export const SignUpContext = React.createContext<SignUpContextModel | null>(null); |
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,44 @@ | ||
export interface Restaurant { | ||
name: string; | ||
address: string; | ||
city: string; | ||
phoneNumber: string; | ||
} | ||
|
||
export interface Beer { | ||
id: string; | ||
name: string; | ||
alcohol: number; | ||
volume: number; | ||
photoUrl: string; | ||
} | ||
|
||
export interface SignUpModel { | ||
userName: string; | ||
password: string; | ||
email: string; | ||
restaurant: Restaurant; | ||
beers: Beer[]; | ||
} | ||
|
||
export const createInitialSignUp = (): SignUpModel => ({ | ||
userName: '', | ||
password: '', | ||
email: '', | ||
restaurant: { | ||
name: '', | ||
address: '', | ||
city: '', | ||
phoneNumber: '', | ||
}, | ||
beers: [], | ||
}); | ||
|
||
export interface SignUpContextModel { | ||
signUpData: SignUpModel; | ||
setUserName: (userName: string) => void; | ||
setPassword: (password: string) => void; | ||
setEmail: (email: string) => void; | ||
setRestaurants: (restaurant: Restaurant) => void; | ||
setBeers: (beers: Beer[]) => void; | ||
} |
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,47 @@ | ||
import React, { useState } from 'react'; | ||
import { SignUpContext } from './sign-up.context'; | ||
import { SignUpModel, createInitialSignUp, Restaurant, Beer } from './sign-up.model'; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
} | ||
|
||
export const SignUpProvider: React.FC<Props> = props => { | ||
const { children } = props; | ||
const [signUpData, setSignUpData] = useState<SignUpModel>(createInitialSignUp); | ||
|
||
const setUserName = (userName: string) => { | ||
setSignUpData({ ...signUpData, userName }); | ||
}; | ||
|
||
const setPassword = (password: string) => { | ||
setSignUpData({ ...signUpData, password }); | ||
}; | ||
|
||
const setEmail = (email: string) => { | ||
setSignUpData({ ...signUpData, email }); | ||
}; | ||
|
||
const setRestaurants = (restaurant: Restaurant) => { | ||
setSignUpData({ ...signUpData, restaurant }); | ||
}; | ||
|
||
const setBeers = (beers: Beer[]) => { | ||
setSignUpData({ ...signUpData, beers }); | ||
}; | ||
|
||
return ( | ||
<SignUpContext.Provider value={{ signUpData, setUserName, setPassword, setEmail, setRestaurants, setBeers }}> | ||
{children} | ||
</SignUpContext.Provider> | ||
); | ||
}; | ||
|
||
export const useSignUpContext = () => { | ||
const context = React.useContext(SignUpContext); | ||
if (context === null) { | ||
throw 'useSignUpContext: looks like you have forgotten to add the provider on top of the app :)'; | ||
} | ||
|
||
return 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { SignUpComponent } from './sign-up.component'; | ||
|
||
import { useSignUpContext } from '#core/providers/sign-up'; | ||
export const SignUpPod: React.FC = () => { | ||
const { signUpData } = useSignUpContext(); | ||
|
||
console.log(signUpData); | ||
return <SignUpComponent />; | ||
}; |