Skip to content

Commit

Permalink
✨ add company
Browse files Browse the repository at this point in the history
  • Loading branch information
shelcia committed Sep 24, 2023
1 parent c6b9713 commit 775f8a7
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 5 deletions.
83 changes: 83 additions & 0 deletions src/pages/admin/company/AddCompany.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from "react";
import { Box, Card, CardContent, Typography } from "@mui/material";
import { CustomTextField } from "../../../components/CustomInputs";
import { useFormik } from "formik";
import * as Yup from "yup";
import { LoadingButton } from "@mui/lab";

const AddCompany = () => {
const validationSchema = Yup.object({
password: Yup.string()
.min(6, "Minimum 6 characters required")
.required("Password is required"),
confirmPassword: Yup.string()
.min(6, "Minimum 6 characters required")
.oneOf([Yup.ref("password"), null], "Passwords must match"),
});

const initialValues = {
name: "",
website: "",
number: 0,
};
const { errors, values, handleChange, handleSubmit, touched } = useFormik({
initialValues,
validationSchema,
onSubmit: (values) => {
// setIsLoading(true);
},
});

return (
<>
<Typography component="h1" variant="h3">
Add Company
</Typography>
<Box sx={{ mt: 3 }}>
<Card>
<CardContent
sx={{ p: 5, display: "flex", gap: 2, flexDirection: "column" }}
>
<CustomTextField
name="name"
label="Name"
placeholder="enter name"
values={values.name}
handleChange={handleChange}
touched={touched}
errors={errors}
/>
<CustomTextField
name="website"
label="Website"
placeholder="enter website"
values={values.website}
handleChange={handleChange}
touched={touched}
errors={errors}
/>
<CustomTextField
name="number"
label="Number"
placeholder="enter number"
values={values.number}
handleChange={handleChange}
touched={touched}
errors={errors}
type="number"
/>
<LoadingButton
onClick={handleSubmit}
variant="contained"
sx={{ mt: 3 }}
>
Add Company
</LoadingButton>
</CardContent>
</Card>
</Box>
</>
);
};

export default AddCompany;
8 changes: 7 additions & 1 deletion src/pages/auth/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ const Login = () => {
localStorage.setItem("CRM-type", res.message.type);
localStorage.setItem("CRM-token", res.message.token);

navigate("/admin_dashboard/contacts");
if (res.message.companyId) {
navigate("/admin_dashboard/contacts");
} else {
navigate("/admin_dashboard/add-company");
localStorage.setItem("CRM-companyId", res.message.companyId);
localStorage.setItem("CRM-company", res.message.company);
}
} else if (res.status === "401") {
localStorage.setItem("CRM-email", user.email);
navigate("/verification?status=not-verified");
Expand Down
22 changes: 18 additions & 4 deletions src/pages/auth/Signup.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from "react";
import { Alert, Box, Button, Typography } from "@mui/material";
import React, { useState } from "react";
import { Alert, Box, Typography } from "@mui/material";
import { Link, useNavigate } from "react-router-dom";
import { useFormik } from "formik";
import * as Yup from "yup";
import toast from "react-hot-toast";
import { apiAuth } from "../../services/models/authModel";
import { CustomAuthInput } from "../../components/CustomInputs";
import { LoadingButton } from "@mui/lab";

const Signup = () => {
const navigate = useNavigate();
const [isLoading, setIsLoading] = useState(false);

const validationSchema = Yup.object().shape({
email: Yup.string()
Expand All @@ -34,8 +36,10 @@ const Signup = () => {
apiAuth.post({ ...user, role: "admin" }, "register").then((res) => {
if (res.status === "200") {
navigate("/verification?status=success");
setIsLoading(false);
} else {
toast.error(res.message);
setIsLoading(false);
}
});
};
Expand Down Expand Up @@ -74,14 +78,24 @@ const Signup = () => {
errors={errors}
type="password"
/>
<Button
<LoadingButton
loading={isLoading}
loadingIndicator="Loading…"
variant="contained"
onClick={handleSubmit}
fullWidth
className="mt-3"
>
Fetch data
</LoadingButton>
{/* <Button
variant="contained"
fullWidth
className="mt-3"
onClick={handleSubmit}
>
Register as Admin
</Button>
</Button> */}
<Box>
<Link to="/login" style={{ textDecoration: "underline" }}>
Have account already? then Signin
Expand Down
8 changes: 8 additions & 0 deletions src/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Layout from "./layout/admin/Layout";
import HomeLayout from "./layout/home/Layout";
import AuthLayout from "./layout/auth/Layout";
import { Outlet } from "react-router-dom";
// import AddCompany from "./pages/admin/company/AddCompany";

const Loadable = (Component) => (props) =>
(
Expand All @@ -31,6 +32,9 @@ const ResetPwd = Loadable(lazy(() => import("./pages/auth/ResetPwd")));

// ADMIN PAGE
// const Dashboard = Loadable(lazy(() => import("./pages/admin/dashboard/Dashboard")));
const AddCompany = Loadable(
lazy(() => import("./pages/admin/company/AddCompany"))
);
const Users = Loadable(lazy(() => import("./pages/admin/users/Users")));
const AddUser = Loadable(lazy(() => import("./pages/admin/users/AddUser")));

Expand Down Expand Up @@ -99,6 +103,10 @@ const routes = [
path: "admin_dashboard",
element: <Layout />,
children: [
{
path: "add-company",
element: <AddCompany />,
},
{
path: "users",
element: <Users />,
Expand Down

1 comment on commit 775f8a7

@vercel
Copy link

@vercel vercel bot commented on 775f8a7 Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

easy-crm – ./

easy-crm.vercel.app
easy-crm-git-master-shelcia.vercel.app
easy-crm-shelcia.vercel.app

Please sign in to comment.