Skip to content

Commit

Permalink
refactor: separation of concerns according to MVP, major modification…
Browse files Browse the repository at this point in the history
… of admin, cart, contact, login and signup
  • Loading branch information
omidhzr committed Dec 11, 2022
1 parent 7cdce3a commit 7a5aec2
Show file tree
Hide file tree
Showing 54 changed files with 2,658 additions and 988 deletions.
268 changes: 249 additions & 19 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"@types/react-redux": "^7.1.24",
"@types/react-toastify": "^4.1.0",
"bootstrap": "^5.1.3",
"dotenv": "^16.0.1",
"firebase": "^9.8.3",
"formik": "^2.2.9",
"get-google-fonts": "^1.2.2",
"moment": "^2.29.4",
"react": "^18.2.0",
"react-bootstrap": "^2.4.0",
"react-dom": "^18.2.0",
"react-icons-kit": "^2.0.0",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"react-stripe-checkout": "^2.6.3",
"react-toastify": "^9.0.8",
"react-toggle-dark-mode": "^1.1.0",
"web-vitals": "^2.1.4"
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
Expand Down
22 changes: 13 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useEffect } from "react";
import { Routes, Route } from "react-router-dom";
import { Home } from "./pages/Home";
import { Signup } from "./pages/Signup";
import { Login } from "./pages/Login";
import ForgotPassword from "./pages/ForgotPassword";
import { Home } from "./containers/Home";
import Signup from "./containers/Signup";
import Login from "./containers/Login";
import ForgotPassword from "./containers/ForgotPassword";
// import Profile from "./components/Profile";
import UpdateProfile from "./pages/UpdateProfile";
import UpdateProfile from "./containers/UpdateProfile";
import ProtectedRoute from "./components/ProtectedRoute";
import { AuthContextProvider } from "./context/AuthContext";
// import AddProducts from "./components/AddProducts";
import Cart from "./pages/Cart";
import Admin from "./pages/Admin";
import Cart from "./containers/Cart";
import Checkout from "./containers/Checkout";
import Contact from "./containers/Contact";
import { Navbar } from "./components/Navbar";
import { Contact } from "./pages/Contact";
import Admin from "./pages/AdminPage";
import PageNotFound from "./pages/PageNotFound";
import { onAuthStateChanged } from "firebase/auth";
import { auth } from "./config/config";
import { useAppDispatch } from "./redux/store";
import { logOut } from "./redux/features/auth/authService";
import { setUser } from "./redux/features/auth/authSlice";


// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ApplicationProps { }

Expand Down Expand Up @@ -47,14 +50,15 @@ const App: React.FunctionComponent<ApplicationProps> = () => {
<Route path="/" element={<Home />} />
<Route path="/signup" element={<Signup />} />
<Route path="/login" element={<Login />} />
<Route path="/forgot-password" element={<ForgotPassword />} />
<Route path="/reset-password" element={<ForgotPassword />} />
{/* <Route path="/profile" element={<ProtectedRoute><Profile /></ProtectedRoute>} /> */}
<Route path="/update-profile" element={<ProtectedRoute><UpdateProfile /></ProtectedRoute>} />
{/* <Route path="/add-products" element={<ProtectedRoute><AddProducts /></ProtectedRoute>} /> */}
<Route path="/admin" element={<ProtectedRoute><Admin /></ProtectedRoute>} />
<Route path="/cart" element={<ProtectedRoute><Cart /></ProtectedRoute>} />
{/* <Route path="/profile" element={<Profile />} /> */}
<Route path="/contact" element={<Contact />} />
<Route path="checkout" element={<ProtectedRoute><Checkout /></ProtectedRoute>} />
<Route path="*" element={<PageNotFound />} />

</Routes>
Expand Down
169 changes: 0 additions & 169 deletions src/components/AddProducts.tsx

This file was deleted.

115 changes: 115 additions & 0 deletions src/components/AddProductsComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React from 'react';
import { Formik } from 'formik';
import { Alert, Button, Form, InputGroup } from 'react-bootstrap';
import * as Yup from 'yup';


const AddProductsComponent = ({ error, handleAddProduct, handleProductImg, progress }: { error: string | null | undefined, handleAddProduct: any, handleProductImg: any, progress: number }) => {


return (
<div className="container">
<div className="row">
<div className="col-md-6 offset-md-3">
<h1 className="text-center">Add Product</h1>
<hr />
<Formik
initialValues={{
title: '',
description: '',
price: 0,
image: null
}}
validationSchema={Yup.object({
title: Yup.string().required('Required'),
description: Yup.string().required('Required'),
price: Yup.number().required('Required'),
})}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
handleAddProduct(values);
setSubmitting(false);
}, 400);
}}
>
{({
values,
errors,
touched,
handleChange,
handleBlur,
handleSubmit,
isSubmitting,
}) => (

<Form onSubmit={handleSubmit}>
<Form.Group className="mb-3" controlId="title">
<Form.Label>Title</Form.Label>
<Form.Control
type="text"
placeholder="Enter title"
name="title"
onChange={handleChange}
onBlur={handleBlur}
value={values.title}
/>
<Form.Control.Feedback type="invalid">
{errors.title && touched.title && errors.title}
</Form.Control.Feedback>
</Form.Group>

<Form.Group className="mb-3" controlId="description">
<Form.Label>Description</Form.Label>
<Form.Control
as="textarea"
rows={3}
placeholder="Enter description"
name="description"
onChange={handleChange}
onBlur={handleBlur}
value={values.description}
/>
{errors.description && touched.description && errors.description}
</Form.Group>

<Form.Group className="mb-3" controlId="price">
<Form.Label>Price</Form.Label>
<Form.Control
type="number"
placeholder="Enter price"
name="price"
onChange={handleChange}
onBlur={handleBlur}
value={values.price}
/>
{errors.price && touched.price && errors.price}
</Form.Group>

<Form.Group className="mb-3" controlId="image">
<Form.Label>Image</Form.Label>

<Form.Control
type="file"
name="image"
onChange={handleProductImg}
onBlur={handleBlur}
/>

{errors?.image && touched?.image && errors?.image}
</Form.Group>

<Button variant="primary" type="submit" disabled={isSubmitting}>
Submit
</Button>
</Form>
)}
</Formik>
</div>
</div>
</div >
);
};


export default AddProductsComponent;
1 change: 1 addition & 0 deletions src/components/CartProduct.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React from 'react';
import { Icon } from 'react-icons-kit';
import { plus } from 'react-icons-kit/feather/plus';
Expand Down
Loading

0 comments on commit 7a5aec2

Please sign in to comment.