Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ali kashefi #25

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17,439 changes: 17,436 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 36 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"description": "Sheypoor frontend challenge",
"main": "sdk/index.js",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand All @@ -15,8 +18,39 @@
"bugs": {
"url": "https://github.com/sheypoor/frontend-challenge/issues"
},
"homepage": "https://github.com/sheypoor/frontend-challenge#readme",
"dependencies": {
"sdk": "file:sdk"
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@hookform/resolvers": "^3.3.0",
"@types/node": "^20.5.6",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@types/react-router-dom": "^5.3.3",
"@types/react-select": "^5.0.1",
"@types/react-toastify": "^4.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.45.4",
"react-icons": "^4.10.1",
"react-router-dom": "^6.15.0",
"react-scripts": "^5.0.1",
"react-select": "^5.7.4",
"react-toastify": "^9.1.3",
"sdk": "file:sdk",
"typescript": "^4.9.5",
"yup": "^1.2.0",
"zustand": "^4.4.1"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
43 changes: 43 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<!-- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<!-- <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> -->
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<!-- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> -->
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

</html>
31 changes: 31 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Routes, Route } from "react-router-dom";
import { ToastContainer } from "react-toastify";
import RouteModel from './models/route'
import routes from './routes/routes'
import useAuth from "./hooks/auth-hook";
import Layout from "./layout/layout";


const App = () => {

useAuth()

return (
<Layout>
<Routes>
{
routes.map((route: RouteModel) => (
<Route
key={route.path}
path={route.path}
element={route.cmp()}
/>
))
}
</Routes>
<ToastContainer />
</Layout>
)
}

export default App
50 changes: 50 additions & 0 deletions src/components/form/elements/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import styled from "@emotion/styled";

interface ButtonProps {
title: string;
disable: boolean;
style?: WrapperProps['style'];
onClick: () => void;
}

const Button = ({ title, disable, style, onClick }: ButtonProps): JSX.Element => {
return <Wrapper style={style}>
<FormButton
disable={disable}
onClick={onClick}
>
{title}
</FormButton>
</Wrapper>;
};

export default Button;

interface WrapperProps {
style?: { [key: string]: string | number };
}

const Wrapper = styled.div<WrapperProps>(({ style }) => ({
boxSizing: 'border-box',
width: '100%',
height: 'max-content',
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'center',
marginTop: '10px',
marginBottom: '10px',
...style,
}));

const FormButton = styled.div<any>(({ disable }) => ({
boxSizing: 'border-box',
display: 'inline-flex',
justifyContent: 'center',
alignItems: 'center',
width: '200px',
height: '40px',
borderRadius: '5px',
cursor: disable ? 'not-allowed' : 'pointer',
backgroundColor: 'green',
color: 'white',
}))
104 changes: 104 additions & 0 deletions src/components/form/elements/number-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { RegisterOptions, UseFormReturn } from "react-hook-form";
import styled from "@emotion/styled";

interface NumberInputProps<EntityModel extends Record<string, any>> {
label: string | JSX.Element;
name: keyof EntityModel;
data: { reactHookFormObject: UseFormReturn<EntityModel>, defaultValue: EntityModel };
registerOptions?: RegisterOptions<EntityModel, any>
style?: WrapperProps['style'];
}

const NumberInput = <EntityModel extends Record<string, any>>({
style,
label,
name,
data,
registerOptions
}: NumberInputProps<EntityModel>): JSX.Element => {
return <Wrapper style={style}>
<Label>{label}</Label>
<NumberInputWrapper
type='number'
key={name.toString()}
defaultValue={data.defaultValue[name]}
error={typeof data.reactHookFormObject.formState.errors[name] !== 'undefined'}
{...data.reactHookFormObject.register(name as any, registerOptions ? { ...registerOptions } : undefined)}
/>
<Error>
{
data.reactHookFormObject.formState.errors &&
data.reactHookFormObject.formState.errors[name] &&
data.reactHookFormObject.formState.errors[name]?.message &&
`${data.reactHookFormObject.formState.errors[name]?.message}`
}
</Error>
</Wrapper>;
};

export default NumberInput;

interface WrapperProps {
style?: { [key: string]: string | number };
}

const Wrapper = styled.div<WrapperProps>(({ style }) => ({
width: '100%',
height: 'max-content',
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'start',
marginTop: '10px',
marginBottom: '10px',
...style,
'> input[type=number]': {
'::-webkit-inner-spin-button': {
'-webkit-appearance': 'none',
margin: 0,
},
'::-webkit-outer-spin-button': {
'-webkit-appearance': 'none',
margin: 0,
}
}
}));

const NumberInputWrapper = styled.input<any>(({ error }) => ({
width: '100%',
height: '50px',
borderRadius: '5px',
fontSize: '20px',
padding: '5px',
marginBottom: '7px',
marginTop: '10px',
boxSizing: 'border-box',
fontFamily: 'sans-serif',
backgroundColor: 'black',
border: `1px solid ${error ? 'red' : 'white'}`,
color: 'white',
}));

const Label = styled.div<any>(() => ({
width: '100%',
height: '15px',
textAlign: 'left',
fontWeight: 600,
fontSize: '20px',
textTransform: 'capitalize',
fontFamily: 'sans-serif',
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'center',
color: 'white',
}));

const Error = styled.div(() => ({
width: '100%',
height: '15px',
textAlign: 'left',
fontWeight: 200,
fontSize: '12px',
color: 'red',
fontFamily: 'sans-serif',
}));
Loading