From b39f4da57d0fffb7f5221862ccb3690531a92043 Mon Sep 17 00:00:00 2001
From: MD MAAZ AHMAD <1hk19cs078@hkbk.edu.in>
Date: Mon, 29 May 2023 14:15:21 +0530
Subject: [PATCH 1/4] feat: signup, feed ui and api
---
db.json | 89 ++++++++++++++++++++---
src/api/auth.js | 6 +-
src/api/profile .js | 10 +++
src/components/Button.js | 0
src/components/fields/Button.js | 2 +-
src/config/url.js | 3 +-
src/index.js | 4 ++
src/views/auth/Login/Form.js | 29 +++++---
src/views/auth/Login/index.js | 12 ++--
src/views/auth/Signup/Signup.js | 122 ++++++++++++++++++++++++++++++++
src/views/auth/Signup/index.js | 24 +++++++
src/views/employees/Form.js | 109 ++++++++++++++++++++++++----
src/views/feed/CreateBlog.js | 24 +++++++
src/views/feed/Form.js | 114 +++++++++++++++++++++++++++++
src/views/feed/feed.scss | 10 ++-
src/views/feed/index.js | 56 ++++++++++++++-
16 files changed, 568 insertions(+), 46 deletions(-)
create mode 100644 src/api/profile .js
delete mode 100644 src/components/Button.js
create mode 100644 src/views/auth/Signup/Signup.js
create mode 100644 src/views/auth/Signup/index.js
create mode 100644 src/views/feed/CreateBlog.js
create mode 100644 src/views/feed/Form.js
diff --git a/db.json b/db.json
index 6dff256..6030d1e 100644
--- a/db.json
+++ b/db.json
@@ -1,12 +1,85 @@
{
- "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"
+ }
+ ],
+ "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..9d083b4 100644
--- a/src/api/auth.js
+++ b/src/api/auth.js
@@ -25,16 +25,12 @@ class AuthApi {
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..d29c02a 100644
--- a/src/components/fields/Button.js
+++ b/src/components/fields/Button.js
@@ -9,7 +9,7 @@ const Button = (props) => {
type={type}
{...rest}
>
- {icon && }{{text}}
+ {icon && }{text}
);
};
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..969c5f6 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 {
@@ -20,19 +20,22 @@ const LoginForm = () => {
useEffect(() => {
if (user) {
console.log("user", user);
- navigate(PROFILE_URL);
+ // 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,
@@ -88,7 +91,6 @@ const LoginForm = () => {
}}
placeholder="Email"
errors={errors}
- required
/>
@@ -105,7 +107,6 @@ const LoginForm = () => {
}}
placeholder="Password"
errors={errors}
- required
/>
@@ -113,13 +114,21 @@ const LoginForm = () => {
Forgot password?
+
-
+
+
+
+
+
+