Skip to content

Commit

Permalink
bug fixed regarding the view profile when not log in
Browse files Browse the repository at this point in the history
  • Loading branch information
SHni99 committed Jul 14, 2022
1 parent cfab63d commit c179060
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 68 deletions.
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@testing-library/user-event": "^12.8.3",
"bootstrap": "^5.2.0-beta1",
"bootstrap-icons": "^1.8.3",
"bootstrap-switch-button-react": "^1.2.0",
"lodash": "^4.17.21",
"moment": "^2.29.3",
"msw": "^0.43.1",
Expand Down
86 changes: 44 additions & 42 deletions src/pages/ProfilePage/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Modal from "react-bootstrap/Modal";

const ViewProfilePage = () => {
const { authData } = useContext(AuthContext);
const { blocked: blockedArray, preferences, email } = authData;
const { blocked: blockedArray, preferences } = authData;
const { state } = useLocation();
const unusedModalState = {
show: false,
Expand All @@ -44,7 +44,6 @@ const ViewProfilePage = () => {
<ProfilePageBody
blockedArray={blockedArray}
preferences={preferences}
email={email}
creator_id={state ? state.creator_id : supabaseClient.auth.user().id}
setModalState={setModalState}
hideModal={hideModal}
Expand All @@ -62,17 +61,17 @@ const ProfilePageBody = ({
setModalState,
hideModal,
blockedArray,
email,
}) => {
const [profileData, setProfileData] = useState({
username: "",
bio: "",
gender: "",
email: "",
});
const [checkUser, setcheckUser] = useState(false);
const [currentValue, setCurrentValue] = useState(false);
const [indexAll, setIndexAll] = useState("");
const checkId = supabaseClient.auth.user()?.id || "";
const checkId = supabaseClient.auth.user()?.id || null;
const ratinghover = useState(true);
const [reviewData, setReviewData] = useState([]);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -230,7 +229,7 @@ const ProfilePageBody = ({
.eq("id", id)
.single();

console.log(operation.preferences.email);

if (error) throw error;
setShow({
email: operation.preferences.email,
Expand All @@ -242,13 +241,12 @@ const ProfilePageBody = ({
}
};

setcheckUser(checkId === creator_id ? false : true);
setcheckUser(checkId !== null ? true : false);
getBlockedStatus(checkId === creator_id ? checkId : creator_id);
getProfile(checkId === creator_id ? checkId : creator_id);
getReview(checkId === creator_id ? checkId : creator_id);
getAllIndex(checkId === creator_id ? checkId : creator_id);
getOptions(checkId === creator_id ? checkId : creator_id);
//getEmail(checkId === creator_id ? checkId : creator_id);
}, [checkId, creator_id, blockedArray]);

const popover = (
Expand Down Expand Up @@ -350,45 +348,49 @@ const ProfilePageBody = ({

<div className="col-lg-8 col-sm-12">
<div className="row">
{!checkUser ? (
<Setting
showModal={(title, body, footer) =>
setModalState({ show: true, title, body, footer })
}
onHide={hideModal}
blockedArray={blockedArray}
></Setting>
) : (
<div className="d-flex justify-center justify-content-lg-end align-items-center mb-5 mt-3 my-lg-0">
{isBlocked ? (
""
) : (
<Button
className="m-2"
onClick={() =>
navigate("/chats", {
state: {
startChatData: {
user_id: creator_id,
name: profileData.username,
src: avatar_url,
},
},
})
}
>
Chat
</Button>
)}
<BlockReportMenu
{checkUser ? (
checkId === creator_id ? (
<Setting
showModal={(title, body, footer) =>
setModalState({ show: true, title, body, footer })
}
hideModal={hideModal}
target_id={creator_id}
onHide={hideModal}
blockedArray={blockedArray}
/>
</div>
></Setting>
) : (
<div className="d-flex justify-center justify-content-lg-end align-items-center mb-5 mt-3 my-lg-0">
{isBlocked ? (
""
) : (
<Button
className="m-2"
onClick={() =>
navigate("/chats", {
state: {
startChatData: {
user_id: creator_id,
name: profileData.username,
src: avatar_url,
},
},
})
}
>
Chat
</Button>
)}
<BlockReportMenu
showModal={(title, body, footer) =>
setModalState({ show: true, title, body, footer })
}
hideModal={hideModal}
target_id={creator_id}
blockedArray={blockedArray}
/>
</div>
)
) : (
""
)}

<Tabs
Expand Down
53 changes: 27 additions & 26 deletions src/pages/UpdateProfilePage/updateProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NavBar from "components/NavBar/navBar";
import profileStyles from "./updateProfile.module.css";
import PersonalAvatar from "components/Avatar/avatar";
import Button from "react-bootstrap/Button";
import Form from "react-bootstrap/Form";
import BootstrapSwitchButton from "bootstrap-switch-button-react";

//retrieve session from loginmain page and call getProfile method if session is read
const UpdateProfilePage = ({ session, showSimpleToast }) => {
Expand Down Expand Up @@ -36,13 +36,11 @@ const UpdateProfilePage = ({ session, showSimpleToast }) => {
"input[name='inlineRadioOptions']:checked"
).value;
const newBio = document.getElementById("bio").value;
const newShowEmail = document.getElementById("showemail").checked;
const newShowGender = document.getElementById("showgender").checked;
const newShowBio = document.getElementById("showbio").checked;

const preferencesUpdate = {
email: newShowEmail,
gender: newShowGender,
bio: newShowBio,
email: emailPreferences,
gender: genderPreferences,
bio: bioPreferences,
};
const updates = {
id: user.id,
Expand Down Expand Up @@ -181,31 +179,29 @@ const ProfilePageBody = (props) => {
className="form-check-input"
type="radio"
name="inlineRadioOptions"
id="gender1"
value="Male"
checked={genderOption === "Male" ? true : ""}
onChange={(e) => setGender(e.target.value)}
/>
<label className="form-check-label inter-medium-sapphire-20px ">
<text className="form-check-label inter-medium-sapphire-20px ">
Male
</label>
</text>
</div>
<div className="form-check form-check-inline">
<input
className="form-check-input"
type="radio"
name="inlineRadioOptions"
id="gender2"
value="Female"
checked={genderOption === "Female" ? true : ""}
onChange={(e) => setGender(e.target.value)}
/>
<label
<text
className="form-check-label inter-medium-red-20px"
htmlFor="inlineRadio2"
>
Female
</label>
</text>
</div>

<div className="mt-8">
Expand Down Expand Up @@ -250,18 +246,20 @@ const ProfilePageBody = (props) => {
<div class="vr d-flex" style={{ height: "800px" }}></div>
</div>
<div className="col-10">
<div className="nunitosans-bold-black-32px text-center">
Preference setting:
<div className="nunitosans-bold-black-32px my-3">
Privacy setting:
</div>
<Form>
<div>
<div className="row my-3">
<label className="col-8 poppins-normal-black-24px">
Show email
</label>
<Form.Check

<BootstrapSwitchButton
className="col"
type="switch"
id="showemail"
onstyle="primary"
width={65}
height={30}
checked={emailPreferences}
onChange={() =>
setEmailPreferences(
Expand All @@ -270,14 +268,16 @@ const ProfilePageBody = (props) => {
}
/>
</div>

<div className="row">
<label className="col-8 poppins-normal-black-24px">
Show gender
</label>
<Form.Check
<BootstrapSwitchButton
className="col"
type="switch"
id="showgender"
onstyle="success"
width={65}
height={30}
checked={genderPreferences}
onChange={() =>
setGenderPreferences(
Expand All @@ -291,10 +291,11 @@ const ProfilePageBody = (props) => {
<label className="col-8 poppins-normal-black-24px">
Show bio
</label>
<Form.Check
<BootstrapSwitchButton
onstyle="warning"
className="col"
type="switch"
id="showbio"
width={65}
height={30}
checked={bioPreferences}
onChange={() =>
setBioPreferences(
Expand All @@ -303,7 +304,7 @@ const ProfilePageBody = (props) => {
}
/>
</div>
</Form>
</div>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit c179060

Please sign in to comment.