Skip to content

Commit

Permalink
User profile update section updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kushwahramkumar2003 committed Feb 4, 2024
1 parent c9ed124 commit 363eb97
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
.env

# Editor directories and files
.vscode/*
Expand Down Expand Up @@ -154,4 +155,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
build
build
.env
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ubuntu

RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get upgrade -y
RUN apt-get install -y nodejs

COPY package.json package.json
COPY package-lock.json package-lock.json
COPY main.js main.js

RUN npm install

ENTRYPOINT [ "node", "main.js" ]
2 changes: 2 additions & 0 deletions _headers
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

*/
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.8"

services:
postgres:
image: postgres # hub.docker.com
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_DB: review
POSTGRES_PASSWORD: password

redis:
image: redis
ports:
- "6379:6379"
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</head>
<body>
<div id="root"></div>
<div id="portal"></div>
<span id="portal"></span>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions src/Components/common/ProfilePicture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const ProfilePicture = ({ avatar }) => {
});
},
onSuccess: (data) => {
dispatch(userActions.setUserInfo(data));
dispatch(userActions.setUserInfo(data?.user));
setOpenCrop(false);
localStorage.setItem("account", JSON.stringify(data));
localStorage.setItem("account", JSON.stringify(data?.user));
queryClient.invalidateQueries({ queryKey: ["profile"] });

toast.success("Profile Photo is Removed");
Expand Down
7 changes: 2 additions & 5 deletions src/Components/crop/CropEasy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import toast from "react-hot-toast";
import { PulseLoader } from "react-spinners";
// eslint-disable-next-line
import { updateProfilePicture } from "../../services/profile";

const CropEasy = ({ photo, setOpenCrop }) => {
const queryClient = useQueryClient();
const dispatch = useDispatch();
Expand All @@ -28,12 +27,10 @@ const CropEasy = ({ photo, setOpenCrop }) => {
});
},
onSuccess: (data) => {
console.log("data : ", data);
dispatch(userActions.setUserInfo(data));
dispatch(userActions.setUserInfo(data?.user));
setOpenCrop(false);
localStorage.setItem("account", JSON.stringify(data));
localStorage.setItem("account", JSON.stringify(data?.user));
queryClient.invalidateQueries({ queryKey: ["profile"] });

toast.success("Profile Photo is updated");
},
onError: (error) => {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/admin/header/NavLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { logout } from "../../../store/actions/userActions";
import { RootState } from "../../../store/types";

const NavLink = () => {
const user = useSelector((state:RootState) => state.user);
const user = useSelector((state: RootState) => state.user);

const navigate = useNavigate();

Expand Down Expand Up @@ -42,7 +42,8 @@ const NavLink = () => {
<div className="Admin-manu">
<div className="Grad-logo">
<h1 className="logo-name-for-admin">QuizGrad</h1>
<img className="rounded-lg"
<img
className="rounded-lg"
src={user?.userInfo?.avatar ? user?.userInfo?.avatar : images.MyAdmin}
alt="profile"
></img>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/signup/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default function Login() {
return signup({ name, email, password });
},
onSuccess: (data) => {
dispatch(userActions.setUserInfo(data));
localStorage.setItem("account", JSON.stringify(data));
dispatch(userActions.setUserInfo(data?.user));
localStorage.setItem("account", JSON.stringify(data?.user));
console.log(data);
naviage("/User");
toast.success("Register successfully");
Expand Down Expand Up @@ -88,7 +88,7 @@ export default function Login() {
<p id="head-2">
<span> Welcome to QuizGrad! </span>
<br />
<span> Please Signup to your account. </span>
<span> Please Sighup to your account. </span>
</p>

<form>
Expand Down
20 changes: 10 additions & 10 deletions src/pages/user/screens/profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useMemo } from "react";
import ProfilePicture from "../../../../Components/common/ProfilePicture";
import { useSelector } from "react-redux";
import { useForm } from "react-hook-form";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useMutation, useQuery } from "@tanstack/react-query";
import { getProfile, updateProfile } from "../../../../services/profile";
import { toast } from "react-hot-toast";
import { PulseLoader } from "react-spinners";
import { RootState } from "../../../../store/types";

const Profile = () => {
const queryClient = useQueryClient();
// const queryClient = useQueryClient();
const userState = useSelector((state: RootState) => state.user);

const {
Expand Down Expand Up @@ -60,7 +60,7 @@ const Profile = () => {
}) => {
return updateProfile({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error

userData: {
name,
email,
Expand All @@ -83,7 +83,7 @@ const Profile = () => {
onSuccess: () => {
// dispatch(userActions.setUserInfo(data));
// localStorage.setItem("account", JSON.stringify(data));
queryClient.invalidateQueries({ queryKey: ["user-profile"] });
// queryClient.invalidateQueries({ queryKey: ["user-profile"] });
toast.success("Profile is updated");
},
onError: (error) => {
Expand All @@ -98,8 +98,8 @@ const Profile = () => {
formState: { errors, isValid },
} = useForm({
defaultValues: {
name: "",
email: "",
name: userState.userInfo.name || "",
email: userState.userInfo.email || "",
password: "",
bio: "",
Birthday: "",
Expand All @@ -116,8 +116,8 @@ const Profile = () => {
},
values: useMemo(() => {
return {
name: profileIsLoading ? "" : profileData?.name,
email: profileIsLoading ? "" : profileData?.email,
name: profileIsLoading ? "" : userState.userInfo?.name,
email: profileIsLoading ? "" : userState.userInfo?.email,
password: "",
bio: profileIsLoading ? "" : profileData?.bio,
Birthday: profileIsLoading ? "" : profileData?.Birthday,
Expand All @@ -133,8 +133,8 @@ const Profile = () => {
Languages: profileIsLoading ? "" : profileData?.Languages,
};
}, [
profileData?.email,
profileData?.name,
userState.userInfo?.email,
userState.userInfo?.name,
profileIsLoading,
profileData?.bio,
profileData?.Birthday,
Expand Down
5 changes: 3 additions & 2 deletions src/services/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ export const getProfile = async () => {
}
};

export const updateProfile = async ({ formData }) => {
export const updateProfile = async ({ userData }) => {
try {
console.log(userData);
console.log("Update Profile called");

const { data } = await axios.put("/api/v1/profile", formData);
const { data } = await axios.put("/api/v1/profile", userData);
return data;
} catch (error) {
console.log(error);
Expand Down
3 changes: 2 additions & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const userInfoFromStorage = localStorage.getItem("account")
: null;

const initialState = {
user: { userInfo: userInfoFromStorage?.user },
user: { userInfo: userInfoFromStorage },
};

//
const store: any = configureStore({
reducer: {
user: userReducer,
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],

})

0 comments on commit 363eb97

Please sign in to comment.