Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…site into marko-profile-page-responsiveness
  • Loading branch information
Marko Savic committed Mar 4, 2022
2 parents 5167573 + 6431758 commit ad32467
Show file tree
Hide file tree
Showing 21 changed files with 300 additions and 171 deletions.
2 changes: 1 addition & 1 deletion components/Consultancy/steps/step1.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Page1 = ({ setstep, setClickRegister, data }) => (
type="button"
onClick={() => {
if (data === null) {
setClickRegister(true);
// setClickRegister(true);
} else {
setstep(1);
}
Expand Down
3 changes: 3 additions & 0 deletions components/homepage/HomepageNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ const HomepageNav = ({
if (session) {
signOut();
}
if (router.pathname === '/settings') {
router.push('/auth');
}
};

useEffect(() => {
Expand Down
70 changes: 39 additions & 31 deletions components/homepage/HomepageNavLogin.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/* eslint-disable */
import axios from "axios";
import { Form, Formik } from "formik";
import { getProviders, getSession, signIn, useSession } from "next-auth/client";
import { useRouter } from "next/router";
import React, { useContext, useEffect, useState } from "react";
import "react-toastify/dist/ReactToastify.css";
import * as Yup from "yup";
import { googleAuth, nextAuth } from "../../contexts/actions/auth/googleAuth";
import login from "../../contexts/actions/auth/login";
import { GlobalContext } from "../../contexts/provider";
import { successToast, errorToast } from "../../contexts/utils/toasts";
import TextField from "../TextField";
import axios from 'axios';
import { Form, Formik } from 'formik';
import {
getProviders, getSession, signIn, useSession,
} from 'next-auth/client';
import { useRouter } from 'next/router';
import React, { useContext, useEffect, useState } from 'react';
import 'react-toastify/dist/ReactToastify.css';
import * as Yup from 'yup';
import { googleAuth, nextAuth } from '../../contexts/actions/auth/googleAuth';
import login from '../../contexts/actions/auth/login';
import { GlobalContext } from '../../contexts/provider';
import { successToast, errorToast } from '../../contexts/utils/toasts';
import TextField from '../TextField';
import updateProfileJSON from '../../contexts/actions/profile/updateProfileJSON';

const HomepageNavLogin = ({ onCloseMobileMenu }) => {
const router = useRouter();
Expand All @@ -23,13 +25,14 @@ const HomepageNavLogin = ({ onCloseMobileMenu }) => {

const {
authDispatch,
profileDispatch,
authState: {
auth: { loading, data },
},
} = useContext(GlobalContext);

useEffect(() => {
const token = window.localStorage.getItem("jwtToken");
const token = window.localStorage.getItem('jwtToken');
let timerId;
if (data || token !== null) {
setLoginSubmit(false);
Expand Down Expand Up @@ -71,7 +74,14 @@ const HomepageNavLogin = ({ onCloseMobileMenu }) => {
login({
email: e.email,
password: e.password,
})(authDispatch);
})(authDispatch).then((res) => {
if (res?.user.isDeactivated === true) {
updateProfileJSON(
res.user._id,
JSON.stringify({ isDeactivated: false }),
)(profileDispatch).then(() => successToast('successfully activated your account'));
}
});
setLoginSubmit(false);
};

Expand All @@ -82,7 +92,7 @@ const HomepageNavLogin = ({ onCloseMobileMenu }) => {
`${process.env.BASE_URI}/user/forgotPassword`,
{
email: e.email,
}
},
);
successToast(request.data.message);
} catch (error) {
Expand All @@ -91,7 +101,7 @@ const HomepageNavLogin = ({ onCloseMobileMenu }) => {
};

return (
<div className={click ? "dropdown-login clicked" : "dropdown-login"}>
<div className={click ? 'dropdown-login clicked' : 'dropdown-login'}>
<button
type="button"
className="dropdown-login-btn-close"
Expand All @@ -112,24 +122,22 @@ const HomepageNavLogin = ({ onCloseMobileMenu }) => {
<img
src="/assets/images/github.svg"
alt="github icon"
onClick={() =>
signIn(providers.github.id, {
callbackUrl: "https://minorityprogrammers.com/auth",
})
}
onClick={() => signIn(providers.github.id, {
callbackUrl: 'https://minorityprogrammers.com/auth',
})}
/>
</div>
</div>
<div className="login-form mt-2">
{!switchToReset && (
<Formik
initialValues={{
email: "",
password: "",
email: '',
password: '',
}}
validationSchema={Yup.object({
email: Yup.string().email("Invalid Email").required("Required"),
password: Yup.string().required("Required"),
email: Yup.string().email('Invalid Email').required('Required'),
password: Yup.string().required('Required'),
})}
onSubmit={onSubmit}
>
Expand Down Expand Up @@ -166,7 +174,7 @@ const HomepageNavLogin = ({ onCloseMobileMenu }) => {
type="submit"
className="btn btn-warning btn-dropdown-filled"
>
{loading ? "Signing In..." : "Sign In"}
{loading ? 'Signing In...' : 'Sign In'}
</button>
</Form>
)}
Expand All @@ -175,10 +183,10 @@ const HomepageNavLogin = ({ onCloseMobileMenu }) => {
{switchToReset && (
<Formik
initialValues={{
email: "",
email: '',
}}
validationSchema={Yup.object({
email: Yup.string().email("Invalid Email").required("Required"),
email: Yup.string().email('Invalid Email').required('Required'),
})}
onSubmit={onReset}
>
Expand All @@ -200,7 +208,7 @@ const HomepageNavLogin = ({ onCloseMobileMenu }) => {
type="submit"
className="btn btn-warning btn-dropdown-filled"
>
{loading ? "Loading..." : "Reset Password"}
{loading ? 'Loading...' : 'Reset Password'}
</button>
</Form>
)}
Expand Down Expand Up @@ -236,7 +244,7 @@ HomepageNavLogin.getInitialProps = async (context) => {

if (session && res && session.accessToken) {
res.writeHead(302, {
Location: "/",
Location: '/',
});
res.end();
return;
Expand Down
12 changes: 11 additions & 1 deletion components/login-signup/form/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import login from '../../../contexts/actions/auth/login';
import { GlobalContext } from '../../../contexts/provider';
import { InputField } from '../../TextField';
import styles from '../../../styles/auth/auth.module.scss';
import updateProfileJSON from '../../../contexts/actions/profile/updateProfileJSON';
import { successToast } from '../../../contexts/utils/toasts';

const Login = ({ setSubmit }) => {
const {
authDispatch,
profileDispatch,
authState: {
auth: { loading },
},
Expand All @@ -24,7 +27,14 @@ const Login = ({ setSubmit }) => {
login({
email: e.email,
password: e.password,
})(authDispatch);
})(authDispatch).then((res) => {
if (res?.user.isDeactivated === true) {
updateProfileJSON(
res.user._id,
JSON.stringify({ isDeactivated: false }),
)(profileDispatch).then(() => successToast('successfully activated your account'));
}
});
};

return (
Expand Down
38 changes: 20 additions & 18 deletions components/settings/ProfileFirstStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import { GlobalContext } from '../../contexts/provider';
import updateProfileJSON from '../../contexts/actions/profile/updateProfileJSON';

const ProfileFirstStep = ({
data, setStep, step, dates, customStyles,
data, setStep, step, dates, customStyles, setData,
}) => {
const [firstName, setFirstName] = useState(data.firstName);
const [lastName, setLastName] = useState(data.lastName);
const [gender, setGender] = useState({ label: data.Gender, value: data.Gender });
const [phoneNumber, setPhoneNumber] = useState(`+${data.phoneNumber}`);
const [firstName, setFirstName] = useState(data ? data.firstName : '');
const [lastName, setLastName] = useState(data ? data.lastName : '');
const [gender, setGender] = useState({ label: data ? data.Gender : '', value: data ? data.Gender : '' });
const [phoneNumber, setPhoneNumber] = useState(data ? data.phoneNumber : '');
const [nationality, setNationality] = useState(
{ label: data.Nationality, value: data.Nationality },
{ label: data ? data.Nationality : '', value: data ? data.Nationality : '' },
);
const [ethnicity, setEthnicity] = useState(data.Ethnicity);
const [ethnicity, setEthnicity] = useState(data ? data.Ethnicity : []);
const [startDate, setStartDate] = useState(dates.birthdayDate);
// update userData
const { profileDispatch } = useContext(GlobalContext);
Expand All @@ -38,26 +38,28 @@ const ProfileFirstStep = ({
setFirstName(data.firstName);
setLastName(data.lastName);
setGender({ label: data.Gender, value: data.Gender });
setPhoneNumber(`+${data.phoneNumber}`);
setPhoneNumber(data.phoneNumber);
setNationality({ label: data.Nationality, value: data.Nationality });
setEthnicity(data.Ethnicity);
};
const submitHandler = (e) => {
e.preventDefault();
const inputStates = {
firstName,
lastName,
phoneNumber,
birthday: startDate,
Ethnicity: ethnicity,
Nationality: nationality.label,
Gender: gender.label,
...(firstName && { firstName }),
...(lastName && { lastName }),
...(phoneNumber && { phoneNumber }),
...(gender.label && { Gender: gender.label }),
...(ethnicity.length > 0 && { Ethnicity: ethnicity }),
...(startDate.toDateString() !== new Date().toDateString() && { birthday: startDate }),
...(nationality.label && { Nationality: nationality.label }),
};
// submit data
updateProfileJSON(

// submit data
const updatedUser = updateProfileJSON(
data._id,
JSON.stringify(inputStates),
)(profileDispatch);
updatedUser.then((res) => setData(res));
setStep(step === 4 ? 4 : step + 1);
};
return (
Expand Down Expand Up @@ -93,7 +95,7 @@ const ProfileFirstStep = ({
isSearchable
onChange={(newValue) => setGender(newValue)}
options={genders}
placeholder="Select Nationality"
placeholder="Select Gender"
value={gender}
/>
</div>
Expand Down
47 changes: 24 additions & 23 deletions components/settings/ProfileFourthStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const DropdownIndicator = () => (
const ProfileFourthStep = ({
data, step, setData,
}) => {
const [googleLink, setGoogleLink] = useState(data.GoogleLink);
const [figmaLink, setFigmaLink] = useState(data.FigmaLink);
const [clickupLink, setClickupLink] = useState(data.ClickupLink);
const [facebookLink, setFacebookLink] = useState(data.FacebookLink);
const [linkedinLink, setLinkedinLink] = useState(data.LinkedinLink);
const [githubLink, setGithubLink] = useState(data.GithubLink);
const [dribbleLink, setDribbleLink] = useState(data.DribbleLink);
const [googleLink, setGoogleLink] = useState(data?.GoogleLink);
const [figmaLink, setFigmaLink] = useState(data?.FigmaLink);
const [clickupLink, setClickupLink] = useState(data?.ClickupLink);
const [facebookLink, setFacebookLink] = useState(data?.FacebookLink);
const [linkedinLink, setLinkedinLink] = useState(data?.LinkedinLink);
const [githubLink, setGithubLink] = useState(data?.GithubLink);
const [dribbleLink, setDribbleLink] = useState(data?.DribbleLink);
// website
const [link, setLink] = useState('');
// new Link
Expand Down Expand Up @@ -58,32 +58,33 @@ const ProfileFourthStep = ({
const router = useRouter();
// Discard Changes
const discard = () => {
setGoogleLink(data.GoogleLink);
setFigmaLink(data.FigmaLink);
setClickupLink(data.ClickupLink);
setFacebookLink(data.FacebookLink);
setLinkedinLink(data.LinkedinLink);
setGithubLink(data.GithubLink);
setDribbleLink(data.DribbleLink);
setGoogleLink(data?.GoogleLink);
setFigmaLink(data?.FigmaLink);
setClickupLink(data?.ClickupLink);
setFacebookLink(data?.FacebookLink);
setLinkedinLink(data?.LinkedinLink);
setGithubLink(data?.GithubLink);
setDribbleLink(data?.DribbleLink);
};
// Handlers
// Update Profile
const submitHandler = async (e) => {
e.preventDefault();
const inputStates = {
GoogleLink: googleLink,
FacebookLink: facebookLink,
GithubLink: githubLink,
DribbleLink: dribbleLink,
FigmaLink: figmaLink,
ClickupLink: clickupLink,
LinkedinLink: linkedinLink,
...(googleLink && { GoogleLink: googleLink }),
...(facebookLink && { FacebookLink: facebookLink }),
...(githubLink && { GithubLink: githubLink }),
...(dribbleLink && { DribbleLink: dribbleLink }),
...(figmaLink && { FigmaLink: figmaLink }),
...(clickupLink && { ClickupLink: clickupLink }),
...(linkedinLink && { LinkedinLink: linkedinLink }),
};
// submit data
updateProfileJSON(
// submit data
const updatedUser = updateProfileJSON(
data._id,
JSON.stringify(inputStates),
)(profileDispatch);
updatedUser.then((res) => setData(res));
const slug = data?.userName;
if (slug) {
router.push(`/user/${slug}`);
Expand Down
Loading

1 comment on commit ad32467

@vercel
Copy link

@vercel vercel bot commented on ad32467 Mar 4, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.