This repository has been archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sign In Page refactor with native SC
- Loading branch information
1 parent
f43f356
commit 4014013
Showing
24 changed files
with
880 additions
and
10 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
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,108 @@ | ||
import React, { useEffect, useState, lazy, Suspense, Fragment } from 'react'; | ||
import Container from './components/Container'; | ||
import { ThemeProvider } from 'styled-components/native'; | ||
import { Toaster } from 'react-hot-toast'; | ||
import { mergeDeep, defaultDictionary } from '../utils'; | ||
import { IStyles, IAuth } from '../uiTypes'; | ||
import useEasybase from '../../useEasybase'; | ||
|
||
const DefaultSignIn = lazy(() => import('./pages/SignIn')); | ||
const DefaultSignUp = lazy(() => import('./pages/SignUp')); | ||
const DefaultForgotPassword = lazy(() => import('./pages/ForgotPassword')); | ||
|
||
export default function ({ theme, customStyles, children, dictionary, signUpFields }: IAuth): JSX.Element { | ||
const [themeVal, setThemeVal] = useState<any>({}); | ||
|
||
const [currentPage, setCurrentPage] = useState<"SignIn" | "SignUp" | "ForgotPassword" | "ForgotPasswordConfirm">("SignIn"); | ||
const { isUserSignedIn } = useEasybase(); | ||
|
||
useEffect(() => { | ||
try { | ||
document.body.style.margin = "0px"; | ||
} catch (_) { } | ||
async function mounted() { | ||
let loadedTheme: IStyles = {}; | ||
if (theme === "minimal-dark") { | ||
const _theme = (await import('../themes/minimal-dark')).default; | ||
if (_theme.init) { | ||
_theme.init() | ||
} | ||
loadedTheme = _theme; | ||
} else if (theme === "material") { | ||
const _theme = (await import('../themes/material')).default; | ||
if (_theme.init) { | ||
_theme.init() | ||
} | ||
loadedTheme = _theme; | ||
} else { | ||
// catch all | ||
const _theme = (await import('../themes/minimal')).default; | ||
if (_theme.init) { | ||
_theme.init() | ||
} | ||
loadedTheme = _theme; | ||
} | ||
|
||
if (customStyles) { | ||
loadedTheme = mergeDeep(loadedTheme, customStyles) | ||
} | ||
|
||
setThemeVal(loadedTheme) | ||
} | ||
mounted(); | ||
}, [theme]) | ||
|
||
if (isUserSignedIn()) { | ||
return <Fragment>{children}</Fragment> | ||
} | ||
|
||
const getCurrentPage = () => { | ||
switch (currentPage) { | ||
case "SignIn": | ||
return ( | ||
<Suspense fallback={<Fragment />}> | ||
<DefaultSignIn | ||
setCurrentPage={setCurrentPage} | ||
dictionary={typeof dictionary === "object" ? { ...defaultDictionary, ...dictionary } : defaultDictionary} | ||
/> | ||
</Suspense> | ||
) | ||
case "SignUp": | ||
return ( | ||
<Suspense fallback={<Fragment />}> | ||
<DefaultSignUp | ||
setCurrentPage={setCurrentPage} | ||
dictionary={typeof dictionary === "object" ? { ...defaultDictionary, ...dictionary } : defaultDictionary} | ||
signUpFields={typeof signUpFields === "object" ? signUpFields : {}} | ||
/> | ||
</Suspense> | ||
) | ||
case "ForgotPassword": | ||
return ( | ||
<Suspense fallback={<Fragment />}> | ||
<DefaultForgotPassword | ||
setCurrentPage={setCurrentPage} | ||
dictionary={typeof dictionary === "object" ? { ...defaultDictionary, ...dictionary } : defaultDictionary} | ||
/> | ||
</Suspense> | ||
) | ||
default: | ||
return <React.Fragment />; | ||
} | ||
} | ||
|
||
return ( | ||
<ThemeProvider theme={themeVal}> | ||
<Container> | ||
<Toaster toastOptions={{ style: { fontFamily: 'inherit', ...(themeVal.toast ? { ...themeVal.toast } : {}) } }} /> | ||
{/* {getCurrentPage()} */} | ||
<Suspense fallback={<Fragment />}> | ||
<DefaultSignIn | ||
setCurrentPage={setCurrentPage} | ||
dictionary={typeof dictionary === "object" ? { ...defaultDictionary, ...dictionary } : defaultDictionary} | ||
/> | ||
</Suspense> | ||
</Container> | ||
</ThemeProvider> | ||
) | ||
} |
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,16 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components/native'; | ||
|
||
const Container = styled.View((props: any) => ({ | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
...(props.theme.container ? { ...props.theme.container } : {}) | ||
})) | ||
|
||
export default function (props: any) { | ||
return ( | ||
<Container>{props.children}</Container> | ||
) | ||
} |
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,8 @@ | ||
import React from 'react'; | ||
import Input from './internal/Input'; | ||
|
||
export default function(props: any) { | ||
return ( | ||
<Input label="Email" autoComplete="email" {...props} type="email" required /> | ||
) | ||
} |
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 React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const ErrorText = styled.p(props => ({ | ||
marginTop: 5, | ||
marginBottom: -5, | ||
fontSize: 12, | ||
fontWeight: 500, | ||
color: 'red', | ||
height: 0, | ||
overflow: 'visible', | ||
...(props.theme.errorText ? { ...props.theme.errorText } : {}) | ||
})) | ||
|
||
interface IErrorText extends React.HTMLAttributes<HTMLParagraphElement> { | ||
value?: string | undefined; | ||
} | ||
|
||
export default function (props: IErrorText) { | ||
if (props.value && props.value.length) { | ||
return <ErrorText {...props}>{props.value}</ErrorText> | ||
} | ||
return <React.Fragment /> | ||
} |
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,16 @@ | ||
import React from 'react'; | ||
import TextButton from './internal/TextButton'; | ||
import styled from 'styled-components/native'; | ||
|
||
const ForgotPassword = styled(TextButton)(props => ({ | ||
marginTop: -53, | ||
marginBottom: 53, | ||
display: 'flex', | ||
...(props.theme.forgotPassword ? { ...props.theme.forgotPassword } : {}) | ||
})) | ||
|
||
export default function (props: any) { | ||
return ( | ||
<ForgotPassword {...props} /> | ||
) | ||
} |
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,31 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components/native'; | ||
|
||
const Form = styled.View((props: any) => ({ | ||
display: "flex", | ||
justifyContent: "center", | ||
minWidth: 300, | ||
width: 380, | ||
padding: '33px 55px', | ||
boxShadow: '0 5px 10px 0 rgb(0 0 0 / 10%)', | ||
borderRadius: 10, | ||
flexDirection: 'column', | ||
fontFamily: "inherit", | ||
margin: '6% auto 50px', | ||
'@media (max-width: 520px)': { | ||
margin: '0px !important', | ||
position: 'fixed !important', | ||
top: 0, | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
width: 'initial !important' | ||
}, | ||
...(props.theme.form ? { ...props.theme.form } : {}) | ||
})) | ||
|
||
export default function (props: any) { | ||
return ( | ||
<Form {...props}>{props.children}</Form> | ||
) | ||
} |
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,27 @@ | ||
import React from 'react'; | ||
import { UseFormRegisterReturn } from 'react-hook-form'; | ||
import styled from 'styled-components'; | ||
import Label from './internal/Label'; | ||
import Select from './internal/Select'; | ||
|
||
const GenderSelect = styled(Select)(props => ({ | ||
boxSizing: "border-box", | ||
...(props.theme.genderSelect ? { ...props.theme.genderSelect } : {}) | ||
})) | ||
|
||
const Root = styled.div({ | ||
position: "relative" | ||
}) | ||
|
||
interface ISelect extends React.SelectHTMLAttributes<HTMLSelectElement> { | ||
register(): UseFormRegisterReturn; | ||
} | ||
|
||
export default function (props: ISelect) { | ||
return ( | ||
<Root> | ||
<Label htmlFor="select-gender">Gender *</Label> | ||
<GenderSelect id="select-gender" {...props} options={["Male", "Female", "Prefer not to say"]} /> | ||
</Root> | ||
) | ||
} |
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,21 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components/native'; | ||
|
||
const HeaderText = styled.Text((props: any) => ({ | ||
fontFamily: "inherit", | ||
fontSize: 24, | ||
fontWeight: 500, | ||
letterSpacing: -.2, | ||
marginBlockStart: '0.67em', | ||
marginBlockEnd: '0.67em', | ||
marginInlineStart: 0, | ||
marginInlineEnd: 0, | ||
marginTop: '16px !important', | ||
...(props.theme.headerText ? { ...props.theme.headerText } : {}) | ||
})) | ||
|
||
export default function (props: any) { | ||
return ( | ||
<HeaderText {...props} /> | ||
) | ||
} |
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,8 @@ | ||
import React from 'react'; | ||
import Input from './internal/Input'; | ||
|
||
export default function(props: any) { | ||
return ( | ||
<Input label="Password" {...props} type="password" required /> | ||
) | ||
} |
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,14 @@ | ||
import React from 'react'; | ||
import TextButton from './internal/TextButton'; | ||
import styled from 'styled-components/native'; | ||
|
||
const SecondaryButton = styled(TextButton)(props => ({ | ||
margin: '15px', | ||
...(props.theme.secondaryButton ? { ...props.theme.secondaryButton } : {}) | ||
})) | ||
|
||
export default function (props: any) { | ||
return ( | ||
<SecondaryButton {...props} /> | ||
) | ||
} |
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,18 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
const SecondaryText = styled.h2(props => ({ | ||
fontFamily: "inherit", | ||
fontSize: 15, | ||
fontWeight: 300, | ||
letterSpacing: -.2, | ||
lineHeight: '20px', | ||
whiteSpace: 'normal', | ||
...(props.theme.secondaryText ? { ...props.theme.secondaryText } : {}) | ||
})) | ||
|
||
export default function (props: React.HTMLAttributes<HTMLHeadingElement>) { | ||
return ( | ||
<SecondaryText {...props} /> | ||
) | ||
} |
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,21 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components/native'; | ||
|
||
const Spacer = styled.View({}); | ||
|
||
interface ISpacer { | ||
size?: "xlarge" | "large" | "medium" | "small" | ||
} | ||
|
||
export default function (props: ISpacer) { | ||
switch (props.size) { | ||
case "xlarge": | ||
return <Spacer style={{ height: 64 }} /> | ||
case "large": | ||
return <Spacer style={{ height: 58 }} /> | ||
case "small": | ||
return <Spacer style={{ height: 16 }} /> | ||
default: | ||
return <Spacer style={{ height: 37 }} /> | ||
} | ||
} |
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,25 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components/native'; | ||
|
||
const SubmitButtonRoot = styled.View((props: any) => props.theme.submitButtonRoot ? props.theme.submitButtonRoot : {}); | ||
|
||
const SubmitButton = styled.Button((props: any) => ({ | ||
position: 'relative', | ||
border: "none", | ||
verticalAlign: "middle", | ||
textAlign: "center", | ||
textOverflow: "ellipsis", | ||
overflow: "hidden", | ||
outline: "none", | ||
cursor: "pointer", | ||
boxSizing: 'border-box', | ||
...(props.theme.submitButton ? { ...props.theme.submitButton } : {}) | ||
})) | ||
|
||
export default function (props: any) { | ||
return ( | ||
<SubmitButtonRoot> | ||
<SubmitButton type="submit" {...props} /> | ||
</SubmitButtonRoot> | ||
) | ||
} |
Oops, something went wrong.