Skip to content

Commit

Permalink
refactor: changes in edit user for public/ private profile (#278)
Browse files Browse the repository at this point in the history
* feat:public profile features

Signed-off-by: pranalidhanavade <[email protected]>

* feat:changes in edit organization details model

Signed-off-by: pranalidhanavade <[email protected]>

* implemented public private selection in edit profile functionality

Signed-off-by: @nishad.shirsat <[email protected]>

---------

Signed-off-by: pranalidhanavade <[email protected]>
Signed-off-by: @nishad.shirsat <[email protected]>
Co-authored-by: pranalidhanavade <[email protected]>
  • Loading branch information
2 people authored and GHkrishna committed Sep 18, 2023
1 parent 2ce63f7 commit 6d15f69
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
16 changes: 15 additions & 1 deletion src/components/Profile/DisplayUserProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { UserProfile } from "./interfaces";
import CustomAvatar from '../Avatar'
import type { UserProfile } from "./interfaces";

interface DisplayUserProfileProps {
toggleEditProfile: () => void;
Expand Down Expand Up @@ -76,6 +76,20 @@ interface DisplayUserProfileProps {
</div>
</div>
</li>
<li className="py-3">
<div className="flex items-center space-x-4">

<div className="flex-1 min-w-0">
<p className="text-lg font-normal text-gray-500 truncate dark:text-gray-400">
Public view
</p>
<p className="text-lg text-black truncate dark:text-white">

{userProfileInfo?.publicProfile ? " Public" : "Private"}
</p>
</div>
</div>
</li>
</ul>
</div>
</div>
Expand Down
53 changes: 28 additions & 25 deletions src/components/Profile/EditUserProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import * as yup from "yup"

import { Avatar, Button, Label } from "flowbite-react";
import { Field, Form, Formik, FormikHelpers } from "formik";
import { IMG_MAX_HEIGHT, IMG_MAX_WIDTH, apiStatusCodes, imageSizeAccepted, storageKeys } from "../../config/CommonConstant";
import { SetStateAction, useEffect, useState } from "react";
import type { UserProfile } from "./interfaces";
import { calculateSize, dataURItoBlob } from "../../utils/CompressImage";
import { getFromLocalStorage, getUserProfile, updateUserProfile } from "../../api/Auth";
import { IMG_MAX_HEIGHT, IMG_MAX_WIDTH, apiStatusCodes, imageSizeAccepted, storageKeys } from "../../config/CommonConstant";

import type { AxiosResponse } from "axios";
import CustomAvatar from '../Avatar'
import { calculateSize, dataURItoBlob } from "../../utils/CompressImage";
import { Avatar, Button, Label } from "flowbite-react";
import { Field, Form, Formik, FormikHelpers } from "formik";
import type { UserProfile } from "./interfaces";
import { asset } from "../../lib/data";
import * as yup from "yup"

interface Values {
profileImg: string;
firstName: string;
lastName: string;
email: string;
radio1: string | boolean;
}

interface ILogoImage {
Expand All @@ -33,13 +34,14 @@ const UpdateUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }

const [loading, setLoading] = useState<boolean>(false)
const [isImageEmpty, setIsImageEmpty] = useState(true)

const [isPublic, setIsPublic] = useState(true)

const [initialProfileData, setInitialProfileData] = useState({
profileImg: userProfileInfo?.profileImg || "",
firstName: userProfileInfo?.firstName || "",
lastName: userProfileInfo?.lastName || "",
email: userProfileInfo?.email || "",
radio1: userProfileInfo?.publicProfile?.toString()

email: userProfileInfo?.email || ""
})
const [logoImage, setLogoImage] = useState<ILogoImage>({
logoFile: '',
Expand All @@ -56,8 +58,7 @@ const UpdateUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }
profileImg: userProfileInfo?.profileImg || "",
firstName: userProfileInfo.firstName || '',
lastName: userProfileInfo.lastName || '',
email: userProfileInfo?.email,
radio1: userProfileInfo?.publicProfile.toString()
email: userProfileInfo?.email
});

setLogoImage({
Expand Down Expand Up @@ -153,21 +154,22 @@ const UpdateUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }
setLoading(true)

const userData = {
id: userProfileInfo?.id as number,
firstName: values.firstName,
lastName: values.lastName,
email: values.email,
profileImg: logoImage?.imagePreviewUrl as string || values?.profileImg,
publicProfile:values?.radio1
isPublic
}

const resUpdateUserDetails = await updateUserProfile(userData)
setLoading(false)

const { data } = resUpdateUserDetails as AxiosResponse

updateProfile(userData);

setLoading(false)

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
updateProfile(userData);
}
}

const validationSchema = yup.object().shape({
Expand Down Expand Up @@ -199,7 +201,6 @@ const UpdateUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }
if (!values.firstName || !values.lastName) {
return;
}
values['radio1'] = values?.radio1 === 'true' ? true : false
updateUserDetails(values);
toggleEditProfile();

Expand Down Expand Up @@ -329,13 +330,14 @@ const UpdateUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }
value="Profile View"
/>
</div>
<Field
<input
className=""
type="radio"
checked={isPublic === false}
onChange={() => setIsPublic(false)}
id="private"
name="radio1"
value="true"
/>
name="private"
/>
<span className="ml-2 text-gray-900">Private
<span className="block pl-6 text-gray-500 text-sm">Only the connected organization can see you organization details</span>
</span>
Expand All @@ -349,12 +351,13 @@ const UpdateUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }
value=""
/>
</div>
<Field
<input
className=""
type="radio"
onChange={() => setIsPublic(true)}
checked={isPublic === true}
id="public"
name="radio1"
value="false"
name="public"
/>
<span className="ml-2 text-gray-900 ">Public
<span className="block pl-6 text-gray-500 text-sm">Your profile and organization details can be seen by everyone</span></span>
Expand Down
11 changes: 6 additions & 5 deletions src/components/Profile/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ export interface UserEmail {

export interface UserProfile {
id: number
profileImg: string
username: string
profileImg?: string
username?: string
email: string
firstName: string
lastName: string
isEmailVerified: boolean
keycloakUserId: string
publicProfile:boolean
isEmailVerified?: boolean
keycloakUserId?: string
publicProfile?: boolean
isPublic?:boolean
}
5 changes: 2 additions & 3 deletions src/components/organization/EditOrgdetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
.trim(),
description: yup
.string()
.min(2, 'Organization name must be at least 2 characters')
.max(600, 'Organization name must be at most 255 characters')
.min(2, 'Organization description must be at least 2 characters')
.max(600, 'Organization description must be at most 255 characters')
.required('Description is required')
})}
validateOnBlur
Expand All @@ -240,7 +240,6 @@ const EditOrgdetailsModal = (props: EditOrgdetailsModalProps) => {
values: Values,
{ resetForm }: FormikHelpers<Values>
) => {

submitUpdateOrganization(values)
}}
>
Expand Down

0 comments on commit 6d15f69

Please sign in to comment.