diff --git a/db.json b/db.json index 6dff256..cbd9977 100644 --- a/db.json +++ b/db.json @@ -1,12 +1,115 @@ { - "user": { - "id": 1, - "name": "Anup", - "email": "anup.singh@gmail.com", - "password": "123123123", - "profilePhoto": "", - "phonme": "98181311488" - }, + "user": [ + { + "name": "Niraj yadav", + "phone": "8102162627", + "email": "Niraj@gamil.com", + "password": "123456", + "profilePhoto": { + "0": {} + }, + "id": "11ad4790-33bb-4fb1-84e1-c2d3dbfcedd5" + }, + { + "name": "vikash", + "phone": "8102162627", + "email": "Rupesh@gamil.com", + "password": "123123123", + "profilePhoto": { + "0": {} + }, + "id": "8d62203a-2e0f-45bf-b0b0-094da9d78758" + }, + { + "name": "md maaz", + "phone": "08102162627", + "email": "Maa12@gmail.com", + "password": "123456", + "profilePhoto": { + "0": {} + }, + "id": "b733170b-039c-44e8-8561-964d7b4cd986" + }, + { + "name": "Anup", + "phone": "12312313", + "email": "anup.singh2071@gmail.com", + "password": "12312313", + "profilePhoto": { + "0": {} + }, + "id": "a615e268-bd88-4f70-a9c6-822d92261cf5" + }, + { + "name": "Anup Kumar Singh", + "phone": "699999", + "email": "anup.singh71@gmail.com", + "password": "123123123", + "profilePhoto": { + "0": {} + }, + "id": "d2100bb1-009e-4ea3-b92a-66fb440987d1" + } + ], + "blog": [ + { + "id": 1, + "user_id": 12, + "title": "Art", + "description": "User Interface Designer", + "location": "New York", + "workType": "Full-Time", + "createdAt": "2h ago" + }, + { + "title": "Finance", + "description": "Upgrade your finacial score", + "location": "Gremany", + "workType": "Full Time", + "createdAt": "09:12", + "id": "047d6e54-4d0e-4c00-a895-9036f522c7ce" + }, + { + "title": "Medical", + "description": "Medical Science", + "location": "India", + "workType": "Part Time", + "createdAt": "09:16", + "id": "327198a3-088d-47c5-a536-5a708a6d04cf" + }, + { + "title": "Marketing", + "description": "Markeing experience", + "location": "Norway", + "workType": "Full Time", + "createdAt": "21:17", + "id": "27f45704-b9aa-464b-911a-e0170d2045cb" + }, + { + "title": "sports", + "description": "cricket", + "location": "Banglore ", + "workType": "Full Time", + "createdAt": "20:49", + "id": "a4d03cfb-b51e-4287-aebc-f9f956adf8f1" + }, + { + "title": "Java Developer", + "description": "FullStack Java Developer", + "location": "INdia", + "workType": "Full Time", + "createdAt": "07:32", + "id": "e41fbadc-7fef-4c18-bd1c-cfef262cfc74" + }, + { + "title": "Sports", + "description": "Football", + "location": "India", + "workType": "Full Time", + "createdAt": "16:06", + "id": "14a3f625-9386-4e78-a200-9f2ac9973afe" + } + ], "employees": [ { "_id": 1, diff --git a/src/api/auth.js b/src/api/auth.js index 7cd561b..2d018f0 100644 --- a/src/api/auth.js +++ b/src/api/auth.js @@ -6,8 +6,12 @@ class AuthApi { return axios.get(`/user/`, params) } - static signup = (params) => { - return axios.post(`/user/`, params) + static signup = (data) => { + return axios({ + method: 'post', + url: `${BASE_URL}/user`, + data: data + }) } static createBlog = (blog) => { @@ -18,23 +22,19 @@ class AuthApi { }) } - static getBlog = (blog) => { - return axios.get(`${BASE_URL}/blog`, blog) + static getBlog = (blog, page=1, limit=10) => { + return axios.get(`${BASE_URL}/blog?_page=${page}&_limit=${limit}`, blog) } static signin = (data) => { return axios.post(`${base}/auth/signin`,data) } - static Register = (data) => { return axios.post(`${base}/register`, data); }; - static Logout = (data) => { return axios.post(`${base}/logout`, data, { headers: { Authorization: `${data.token}` } }); }; } - let base = "users"; - -export default AuthApi; +export default AuthApi; \ No newline at end of file diff --git a/src/api/profile .js b/src/api/profile .js new file mode 100644 index 0000000..2357d59 --- /dev/null +++ b/src/api/profile .js @@ -0,0 +1,10 @@ +import axios from "./index"; + +class ProfileApi { + + static edit = (id, body) => { + return axios.put(`/user/${id}`, body) + } +} + +export default ProfileApi; \ No newline at end of file diff --git a/src/components/Button.js b/src/components/Button.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/components/fields/Button.js b/src/components/fields/Button.js index 690c467..27c761a 100644 --- a/src/components/fields/Button.js +++ b/src/components/fields/Button.js @@ -5,11 +5,11 @@ const Button = (props) => { props; return ( ); }; diff --git a/src/config/url.js b/src/config/url.js index 1d2c9ec..6cea4c4 100644 --- a/src/config/url.js +++ b/src/config/url.js @@ -10,5 +10,6 @@ const PROFILE_URL = '/profile'; // Auth const LOGIN_URL = '/login'; +const SIGNUP_URL = '/signup'; -export {ROOT_URL, EMPLOYEE_FORM, EMPLOYEE_LIST_URL, LOGIN_URL, FEED_URL, PROFILE_URL}; \ No newline at end of file +export {ROOT_URL, EMPLOYEE_FORM, EMPLOYEE_LIST_URL, LOGIN_URL, FEED_URL, PROFILE_URL, SIGNUP_URL}; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 613079a..13c392a 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,8 @@ import App from "./App"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import Feed from "./views/feed"; import Login from "./views/auth/Login"; +import Signup from "./views/auth/Signup/index"; +import CreateBlog from "./views/feed/CreateBlog" import Dashboard from "./views/dashboard"; import EmployeeForm from "./views/employees/Form"; import { Profile } from "./views/employees/Profile"; @@ -38,6 +40,8 @@ root.render( } /> } /> } /> + } /> + } /> diff --git a/src/views/auth/Login/Form.js b/src/views/auth/Login/Form.js index 52ddb47..a870018 100644 --- a/src/views/auth/Login/Form.js +++ b/src/views/auth/Login/Form.js @@ -3,10 +3,10 @@ import { useForm } from "react-hook-form"; import AuthApi from "../../../api/auth"; import Swal from "sweetalert2"; import { useAuth } from "../../../context/AuthProvider"; -import { useNavigate } from "react-router-dom"; -import Button from "../../../components/fields/Button"; +import { useNavigate, Link } from "react-router-dom"; import { PROFILE_URL } from "../../../config/url"; import InputField from "../../../components/fields/InputField"; +import Button from "../../../components/fields/Button"; const LoginForm = () => { const { @@ -17,22 +17,25 @@ const LoginForm = () => { const { user, setUser } = useAuth(); const navigate = useNavigate(); - useEffect(() => { - if (user) { - console.log("user", user); - navigate(PROFILE_URL); - } - }, [user]); + // useEffect(() => { + // if (user) { + // console.log("user", user); + // // navigate(PROFILE_URL); + // } + // }, [user]); + + const onSubmit = (data) => { // setUser(data); - console.log("user =---->", JSON.stringify(data)); + localStorage.setItem("user =---->", JSON.stringify(data)); - // call an API to login + // call an API to login // when api gives success response, navigate to root url - AuthApi.login(data).then((result) => { - console.log("signin -> ", result); + AuthApi.login(data).then((result) => { + console.log("signin -> ", result); if (result.status === 200) { + navigate(PROFILE_URL); Swal.fire({ timer: 1500, showConfirmButton: false, @@ -105,7 +108,6 @@ const LoginForm = () => { }} placeholder="Password" errors={errors} - required />
@@ -113,13 +115,21 @@ const LoginForm = () => { Forgot password?
- -
+ + + +
+ + ); +}; + +export default SignupForm; diff --git a/src/views/auth/Signup/index.js b/src/views/auth/Signup/index.js new file mode 100644 index 0000000..9420868 --- /dev/null +++ b/src/views/auth/Signup/index.js @@ -0,0 +1,24 @@ +import React,{useState} from "react"; +import SignupForm from "./Signup"; +import "../auth.scss"; + +const Signup = () => { + + + return ( +
+
+
+
+
+
Sign Up
+ +
+
+
+
+
+ ); +}; + +export default Signup; diff --git a/src/views/dashboard/index.js b/src/views/dashboard/index.js index f87c468..298c765 100644 --- a/src/views/dashboard/index.js +++ b/src/views/dashboard/index.js @@ -18,6 +18,7 @@ const Dashboard = () => { const [employees, setEmployees] = useState([]); const [selectedEmployee, setSelectedEmployee] = useState(null); const { data, isLoading, error, refetch } = useQuery("employees", EmployeeApi.getAllEmployees, employeesQueryConfig); + const navigate = useNavigate(); const { mode, setMode } = useNavigation(); diff --git a/src/views/employees/Form.js b/src/views/employees/Form.js index 27d0136..f885622 100644 --- a/src/views/employees/Form.js +++ b/src/views/employees/Form.js @@ -1,6 +1,6 @@ import React, { useState } from "react"; import Swal from "sweetalert2"; -import { useForm } from "react-hook-form"; +import { useForm } from "react-hook-form"; import { generateId } from "../../utils"; import { useNavigate } from "react-router-dom"; import InputField from "../../components/fields/InputField"; @@ -195,18 +195,103 @@ const EmployeeForm = ({selectedEmployee = null }) => { {errors.description && This field is required}
- - navigate("/")} - /> - - + + + + + {errors.lastName && This field is required} + + +
+
+ State} + value={selectedState} + onChange={(e) => setSelectedState(e.target.value)} + className="form-control" + options={states} + /> +
+ +
+ City} + value={selectedCity} + onChange={(e) => setSelectedCity(e.target.value)} + className="form-control" + options={cities} + disabled={!selectedState} + /> +
+ +
+ Code} + value={selectedCity} + onChange={(e) => setSelectedCity(e.target.value)} + className="form-control" + options={postalCodes} + disabled={!selectedState} + /> +
+
+ + + {errors.email && This field is required} + + + + {errors.salary && This field is required} + +
+ + + {errors.description && This field is required} +
+ + + navigate("/")} + /> + + ); }; diff --git a/src/views/feed/CreateBlog.js b/src/views/feed/CreateBlog.js new file mode 100644 index 0000000..e07c327 --- /dev/null +++ b/src/views/feed/CreateBlog.js @@ -0,0 +1,24 @@ +import React from "react"; +import BlogForm from "./Form"; +import "../auth/auth.scss"; + +const CreateBlog = () => { + + + return ( +
+
+
+
+
+
Create Your Own Blog!!!
+ +
+
+
+
+
+ ); +}; + +export default CreateBlog; diff --git a/src/views/feed/Form.js b/src/views/feed/Form.js new file mode 100644 index 0000000..7ab0573 --- /dev/null +++ b/src/views/feed/Form.js @@ -0,0 +1,109 @@ +import React, { useState } from "react"; +import { useForm } from "react-hook-form"; +import AuthApi from "../../api/auth"; +import Swal from "sweetalert2"; +import { useAuth } from "../../context/AuthProvider"; +import { generateId } from "../../utils"; +import { useNavigate } from "react-router-dom"; +import { FEED_URL } from "../../config/url"; + +const BlogForm = () => { + const { + register, + handleSubmit, + formState: { errors }, + } = useForm(); + + const navigate = useNavigate(); + + const { user, setUser } = useAuth(); + + const onSubmit = (data) => { + console.log("Invalid data", data); + const newBlog = data; + newBlog.id = generateId(); + + AuthApi.createBlog(newBlog).then((result) => { + if (result.status === 201) { + console.log(result.data); + localStorage.setItem("employees_data", JSON.stringify(data)); + setUser(newBlog); + navigate(FEED_URL); + Swal.fire({ + icon: "success", + title: "Added!", + text: `Your Blog has been Added.`, + showConfirmButton: false, + timer: 3000, + }); + } else { + Swal.fire({ + icon: "failure", + title: "Failed!", + text: `Your Blog has not been Added.`, + showConfirmButton: false, + timer: 3000, + }); + } + }); + }; + + return ( +
+
+ + + {errors.title && Required*} +
+
+ + + {errors.description && Required*} +
+
+ + + {errors.location && Required*} +
+
+ + + {errors.workType && Required*} +
+
+ + + {errors.createdAt && Required*} +
+
+ +
+ ); +}; + +export default BlogForm; diff --git a/src/views/feed/feed.scss b/src/views/feed/feed.scss index f66410b..1aeb3fd 100644 --- a/src/views/feed/feed.scss +++ b/src/views/feed/feed.scss @@ -20,7 +20,15 @@ text-decoration: none; border-bottom: 3px solid transparent; } - + .w-100{ + width: 100%; + } + .m-all-1rem{ + margin: 1rem 1.5rem 1rem 1rem; + } + .f-right{ + float : right; + } .topnav a:hover { color: black; border-bottom: 3px solid red; diff --git a/src/views/feed/index.js b/src/views/feed/index.js index 5801276..99a3a39 100644 --- a/src/views/feed/index.js +++ b/src/views/feed/index.js @@ -1,187 +1,128 @@ -import React from 'react'; -import Header from '../../components/Navbar'; -import './feed.scss'; +import React, { useState, useEffect } from "react"; +import Header from "../../components/Navbar"; +import AuthApi from "../../api/auth"; +import "./feed.scss"; +import { useQuery } from "react-query"; +import { Link } from "react-router-dom"; +import Spinner from "../../layouts/Spinner"; +import Alert from "../../layouts/Alert"; const Feed = () => { + const { data, isLoading, error, refetch } = useQuery("feed", AuthApi.getBlog); + if (isLoading) { + return ; + } + + if (error) { + return ; + } + return ( <> -
+
-
-
-
-
- Creative & Art -
User Experience Designer Employee
-
    -
  • -

    New York, USA

    -
  • -
  • -

    Full Time

    -
  • -
-
-
-

Globe Solution Ltd.

-
- 2h ago -
-
-
-
-
-
-
- Finance & Accounting -
Foreign Language Research Analyst
-
    -
  • -

    New York, USA

    -
  • -
  • -

    Full Time

    -
  • -
-
-
-

Globe Solution Ltd.

-
- 2h ago -
-
-
-
-
-
-
- Medical -
Medical Assistant, East Valley Primary Care
-
    -
  • -

    New York, USA

    -
  • -
  • -

    Full Time

    -
  • -
-
-
-

Globe Solution Ltd.

-
- 2h ago -
-
-
-
-
-
-
- Corporate -
Foreign Language Research Analyst
-
    -
  • -

    New York, USA

    -
  • -
  • -

    Full Time

    -
  • -
-
-
-

Globe Solution Ltd.

-
- 2h ago -
-
-
-
-
-
-
- Marketing -
User Experience Designer Employee
-
    -
  • -

    New York, USA

    -
  • -
  • -

    Full Time

    -
  • -
-
-
-

Globe Solution Ltd.

-
- 2h ago -
-
-
-
+
+ + + +
+
+ {data?.data.map((feed) => (
-
-
- Programming & IT -
Medical Assistant, East Valley Primary Care
-
    -
  • -

    New York, USA

    -
  • -
  • -

    Full Time

    -
  • -
-
-
-

Globe Solution Ltd.

-
- 2h ago -
+
+
+ {feed.title} +
+ {feed.description} +
+
    +
  • +

    + {" "} + {feed.location} +

    +
  • +
  • +

    + + {feed.workType} +

    +
  • +
+
+
+

+ {feed.createdAt} +
+
-
-
- Find More - -
+ ))} + +
+
+ Find More +
+
-
+
); };