Skip to content

Commit

Permalink
fix: profile completions
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalCodes committed Dec 16, 2024
1 parent 6185dde commit 7675bb4
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 27 deletions.
47 changes: 38 additions & 9 deletions src/components/shared/profileCompletion/ProfileCompletion.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* eslint-disable no-unused-vars */
import useProfileCompletion from "@hooks/useProfileCompletion";
import { completeProfileApiCall } from "@service/MilanApi";
import { showSuccessToast } from "@utils/Toasts";
import clsx from "clsx";
import { useState } from "react";
import { RxCross2 } from "react-icons/rx";
import { Button } from "..";
import "./ProfileCompletion.scss";

const ProfileCompletion = ({ edit }) => {
const ProfileCompletion = ({ edit, setShowEditModal, refreshProfileData }) => {
const { errors, validateForm, handleChange, credentials } =
useProfileCompletion();

Expand All @@ -30,14 +32,41 @@ const ProfileCompletion = ({ edit }) => {
<div className="profilecompletion_modal">
<div className="profilecompletion_header">
{edit === false ? (
<>
{" "}
<h1> We&apos;re almost done </h1>
<p>
To make your Organization visible to others, please complete
your profile.
</p>
</>
<div className="profilecompletion_header_top">
<div>
<h1> We&apos;re almost done </h1>
<p>
To make your Organization visible to others, please complete
your profile.
</p>
</div>

<Button
type="submit"
disabled={
!credentials?.description ||
!credentials?.address?.line1 ||
!credentials?.address?.line2 ||
!credentials?.address?.city ||
!credentials?.address?.state ||
!credentials?.address?.country ||
!credentials?.address?.pincode
}
onClickfunction={async () => {
const data = await completeProfileApiCall({
credentials,
});

if (data?.status === 200) {
showSuccessToast(data?.data?.message);
setShowEditModal(false);
refreshProfileData();
}
}}
>
Save
</Button>
</div>
) : (
<div className="profilecompletion_header_edit">
<RxCross2 />
Expand Down
12 changes: 12 additions & 0 deletions src/components/shared/profileCompletion/ProfileCompletion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
z-index: 10;
padding: 10px 1rem;

.profilecompletion_header_top {
display: flex;
align-items: start;
justify-content: space-between;

button {
width: 15%;
font-family: var(--outfit);
}
}

.profilecompletion_header_edit {
display: flex;
align-items: center;
Expand All @@ -57,6 +68,7 @@
font-family: var(--outfit);
width: 15%;
border-radius: 10px;
margin-top: 0;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useProfileCompletion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { STATUSCODE } from "@/static/Constants";
import { UpdateUserApiCall } from "@service/MilanApi";
import { completeProfileApiCall } from "@service/MilanApi";
import { showSuccessToast } from "@utils/Toasts";
import { useState } from "react";

Expand Down Expand Up @@ -76,7 +76,7 @@ const useProfileCompletion = () => {

setErrors(newErrors);

const data = await UpdateUserApiCall({
const data = await completeProfileApiCall({
credentials: {
...updatedCredentials,
config: {
Expand Down
3 changes: 2 additions & 1 deletion src/integrations/ApiEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const API = import.meta.env.VITE_API_URL;
const userEndpoints = {
details: (userName) => `${API}/user?userName=${userName}`,
profile: `${API}/user/profile`,
update: `${API}/user/update`,
update: `${API}/user/update/profile`,
report: `${API}/user/report`,
completeProfile: `${API}/user/completeprofile`,
};

const clubEndpoints = {
Expand Down
32 changes: 21 additions & 11 deletions src/pages/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ const Dashboard = () => {
const [showEditModal, setShowEditModal] = useState(false);
const dispatch = useDispatch();

const { data: profileData } = useSWR(userEndpoints.profile, fetcher, {
onSuccess: (data) => {
dispatch(updateUserData(data));
const { data: profileData, mutate: refreshProfileData } = useSWR(
userEndpoints.profile,
fetcher,
{
onSuccess: (data) => {
dispatch(updateUserData(data?.user));
},
onError: (error) => {
showErrorToast(error?.response?.data?.message);
},
},
onError: (error) => {
showErrorToast(error?.response?.data?.message);
},
});
);

return (
<>
Expand Down Expand Up @@ -60,8 +64,8 @@ const Dashboard = () => {
</button>

<div className="profile_details">
<h2>{profileData?.name}</h2>
<p>{profileData?.description}</p>
<h2>{profileData?.user?.name}</h2>
<p>{profileData?.user?.description}</p>
</div>
</div>

Expand All @@ -75,8 +79,14 @@ const Dashboard = () => {
</div>
</div>

{(profileData?.config?.hasCompletedProfile === false ||
showEditModal === true) && <ProfileCompletion edit={showEditModal} />}
{(profileData?.user?.config?.hasCompletedProfile === false ||
showEditModal === true) && (
<ProfileCompletion
edit={showEditModal}
setShowEditModal={setShowEditModal}
refreshProfileData={refreshProfileData}
/>
)}
</>
);
};
Expand Down
12 changes: 8 additions & 4 deletions src/service/MilanApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ export const ReportProblem = async (credentials) => {
};

// UPDATE USER
export const UpdateUserApiCall = async ({ credentials }) => {
export const completeProfileApiCall = async ({ credentials }) => {
try {
const response = await Axios.patch(userEndpoints.update, credentials, {
withCredentials: true,
});
const response = await Axios.patch(
userEndpoints.completeProfile,
credentials,
{
withCredentials: true,
},
);

return response;
} catch (error) {
Expand Down

0 comments on commit 7675bb4

Please sign in to comment.