diff --git a/.eslintrc.cjs b/.eslintrc.cjs index d6c9537..5be8900 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -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': [ diff --git a/.gitignore b/.gitignore index c9c9d17..f5099cc 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ node_modules dist dist-ssr *.local +.env # Editor directories and files .vscode/* @@ -154,4 +155,5 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* -build \ No newline at end of file +build +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..29d7a40 --- /dev/null +++ b/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/_headers b/_headers index 23eeb75..5cde00d 100755 --- a/_headers +++ b/_headers @@ -1,3 +1,5 @@ /* Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true + +*/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f01fda8 --- /dev/null +++ b/docker-compose.yml @@ -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" diff --git a/index.html b/index.html index 8bd4ed8..2458dfe 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,7 @@
-
+ diff --git a/src/Components/common/ProfilePicture.tsx b/src/Components/common/ProfilePicture.tsx index d045792..3309fdf 100755 --- a/src/Components/common/ProfilePicture.tsx +++ b/src/Components/common/ProfilePicture.tsx @@ -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"); diff --git a/src/Components/crop/CropEasy.tsx b/src/Components/crop/CropEasy.tsx index ad62201..76b23e5 100755 --- a/src/Components/crop/CropEasy.tsx +++ b/src/Components/crop/CropEasy.tsx @@ -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(); @@ -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) => { diff --git a/src/pages/admin/header/NavLink.tsx b/src/pages/admin/header/NavLink.tsx index ba69799..b9f3b0b 100755 --- a/src/pages/admin/header/NavLink.tsx +++ b/src/pages/admin/header/NavLink.tsx @@ -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(); @@ -42,7 +42,8 @@ const NavLink = () => {

QuizGrad

- profile diff --git a/src/pages/signup/SignUp.tsx b/src/pages/signup/SignUp.tsx index 6e3b44a..9fc57a5 100755 --- a/src/pages/signup/SignUp.tsx +++ b/src/pages/signup/SignUp.tsx @@ -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"); @@ -88,7 +88,7 @@ export default function Login() {

Welcome to QuizGrad!
- Please Signup to your account. + Please Sighup to your account.

diff --git a/src/pages/user/screens/profile/Profile.tsx b/src/pages/user/screens/profile/Profile.tsx index d5dbeaf..7495a36 100755 --- a/src/pages/user/screens/profile/Profile.tsx +++ b/src/pages/user/screens/profile/Profile.tsx @@ -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 { @@ -60,7 +60,7 @@ const Profile = () => { }) => { return updateProfile({ // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error + userData: { name, email, @@ -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) => { @@ -98,8 +98,8 @@ const Profile = () => { formState: { errors, isValid }, } = useForm({ defaultValues: { - name: "", - email: "", + name: userState.userInfo.name || "", + email: userState.userInfo.email || "", password: "", bio: "", Birthday: "", @@ -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, @@ -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, diff --git a/src/services/profile.ts b/src/services/profile.ts index 697c7af..b926ceb 100755 --- a/src/services/profile.ts +++ b/src/services/profile.ts @@ -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); diff --git a/src/store/index.ts b/src/store/index.ts index bf77422..e5ab915 100755 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -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, diff --git a/vite.config.ts b/vite.config.ts index 5a33944..7072882 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,4 +4,5 @@ import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], + })