Skip to content

Commit

Permalink
Merge branch 'feature/Lemoncode#27-crear-github-ci-configuracion-basi…
Browse files Browse the repository at this point in the history
…ca' of https://github.com/torresgol10/beer-geek-menu into feature/Lemoncode#27-crear-github-ci-configuracion-basica
  • Loading branch information
torresgol10 committed May 22, 2024
2 parents ecb0f2c + 224ecf0 commit ff197ba
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 5 deletions.
11 changes: 7 additions & 4 deletions intranet/src/app.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { CssBaseline, ThemeProvider } from '@mui/material';

import { AppRouter } from '#core/router';
import { mainTheme } from '#core/theme';
import { SignUpProvider } from '#core/providers/';

export const App = () => {
return (
<ThemeProvider theme={mainTheme}>
<CssBaseline />
<AppRouter />
</ThemeProvider>
<SignUpProvider>
<ThemeProvider theme={mainTheme}>
<CssBaseline />
<AppRouter />
</ThemeProvider>
</SignUpProvider>
);
};
1 change: 1 addition & 0 deletions intranet/src/core/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './sign-up';
2 changes: 2 additions & 0 deletions intranet/src/core/providers/sign-up/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './sign-up.context';
export * from './sign-up.provider';
4 changes: 4 additions & 0 deletions intranet/src/core/providers/sign-up/sign-up.context.tsx
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);
44 changes: 44 additions & 0 deletions intranet/src/core/providers/sign-up/sign-up.model.ts
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;
}
47 changes: 47 additions & 0 deletions intranet/src/core/providers/sign-up/sign-up.provider.tsx
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;
};
5 changes: 4 additions & 1 deletion intranet/src/pods/sign-up/sign-up.pod.tsx
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 />;
};

0 comments on commit ff197ba

Please sign in to comment.