-
Notifications
You must be signed in to change notification settings - Fork 1
Content creator - profile picture functionality added #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 1 commit
7cda8a8
0c25712
19078e3
68cfb62
cf592ed
d816051
89121fd
3758c29
8f8884a
8d03ea5
66a2758
69bce29
dc63e0b
2b10a1c
363e90e
0697d1a
00a36ec
357977b
f7c39a3
a77baea
263cac3
3ef9304
5674165
ffae260
c9acad6
1a89962
098618a
a050999
8d9debb
a3cc570
da89b1f
8f1c853
e85a371
590eea9
7a84bb2
d0ded5f
1e4ea9d
4f4ad53
24e0a09
9f3fa41
698b019
2a782fd
8c4530e
f424f52
3482efe
289ee09
24282f8
10e879a
e82181c
d0ca8f1
46d9dd0
f94bb74
f5ff767
633f164
a3587e8
2942566
aeb9a1a
0c0d06a
2e933ac
c3eb639
65f290c
269e9b7
5487d33
fbad72f
71ffc06
ff746b6
e4cb8f8
79484de
e9cd66d
0819fa5
6c7b801
a621a66
c87c3e5
2c1ba60
2ae240a
9a2a7cb
98f2f56
361942a
9adf6ab
37264fa
8288965
70fd8ff
d99dc89
a0fe523
075b8b1
36d49d4
dc47c62
73f77a5
a14aa27
395978f
beac635
33e0832
24e99af
a496d99
aeb5f72
838a4d9
6c9ecfb
15faa7a
805902f
5caa82f
939f31d
04fbad5
42d87cc
ec2318c
7605dae
841b0ab
ff1facf
aa5f5ad
4639a42
0bc7486
d035e59
308e910
a79d8be
fa9bb21
0c94c6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| //Imports | ||
| import { useEffect, useState } from "react"; | ||
| import { useState } from "react"; | ||
|
|
||
| import Modals from "@/auth/components/Modals"; | ||
|
|
||
| import { BACKEND_URL } from "../../../shared/config/environment"; | ||
| import { getBaseApiUrl } from "../../../shared/config/api-config"; | ||
|
|
||
| //Exporting UI content&structure of | ||
| export default function PersonalInformationForm({ | ||
|
|
@@ -13,19 +13,23 @@ export default function PersonalInformationForm({ | |
| toggleMenu1, | ||
| imageClick, | ||
| handleFileChange, | ||
| handleProfilePictureDelete, | ||
| myRef, | ||
| register, | ||
| handleInputChange, | ||
| profilePictureUrl, | ||
| }: { | ||
| formData: any; | ||
| errors: any; | ||
| handleCharCountBio: any; | ||
| toggleMenu1: any; | ||
| imageClick: any; | ||
| handleFileChange: any; | ||
| handleProfilePictureDelete: any; | ||
RasmusJensen1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| myRef: any; | ||
| register: any; | ||
| handleInputChange: any; | ||
| profilePictureUrl?: string; | ||
| }) { | ||
| //State for pop up modals | ||
| const [isModalOpen, setIsModalOpen] = useState(false); | ||
|
|
@@ -42,31 +46,38 @@ export default function PersonalInformationForm({ | |
| setModalInputValue(numericInput); | ||
| setIntError(!/^[0-9]*$/.test(e.target.value)); | ||
| }; | ||
| const getUserImage = async () => { | ||
| const response = await fetch( | ||
| `http://localhost:8888/api/bucket/${formData.photo}`, | ||
| ); | ||
|
|
||
| // Helper get correct image URL | ||
|
||
| const getImageUrl = (url: string | undefined): string => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exists in media utils |
||
| if (!url) return ""; | ||
| if (url.startsWith('http')) return url; | ||
|
|
||
| let strapiBase = getBaseApiUrl(); | ||
| if (strapiBase.endsWith('/api')) { | ||
| strapiBase = strapiBase.slice(0, -4); | ||
| } | ||
| return `${strapiBase}${url}`; | ||
| }; | ||
| useEffect(() => { | ||
| getUserImage(); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <> | ||
| {/* content of personal information when drop down button is clicked */} | ||
| {toggleMenu1 && ( | ||
| /* Image */ | ||
| <div className="border border-[#166276] p-4 rounded-b-lg text-left bg-white shadow-xl"> | ||
| {/* Display selected image if uploaded, otherwise display icon with initials*/} | ||
| {formData.photo ? ( | ||
| <img | ||
| src={`${BACKEND_URL}/api/bucket/${formData.photo}`} | ||
| className="w-[120px] h-[120px] p-[0px] bg-cyan-800 rounded-[60px] border-2 border-white inline-flex" | ||
| alt="" | ||
| /> | ||
| {profilePictureUrl ? ( | ||
| <div className="relative inline-block"> | ||
| <img | ||
| src={getImageUrl(profilePictureUrl)} | ||
| className="w-[120px] h-[120px] rounded-full border-2 border-white object-cover" | ||
| alt="Profile" | ||
RasmusJensen1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /> | ||
| </div> | ||
| ) : ( | ||
| <div | ||
| onClick={imageClick} | ||
| className="w-[120px] h-[120px] p-[30px] bg-cyan-800 rounded-[60px] border-2 border-white justify-center items-center gap-[30px] inline-flex" | ||
| className="w-[120px] h-[120px] p-[30px] bg-cyan-800 rounded-[60px] border-2 border-white justify-center items-center gap-[30px] inline-flex cursor-pointer" | ||
| > | ||
| <div className="text-white text-4xl font-bold font-['Montserrat']"> | ||
| {formData.UserName.charAt(0).toUpperCase()} | ||
|
|
@@ -82,13 +93,25 @@ export default function PersonalInformationForm({ | |
| style={{ display: "none" }} | ||
| /> | ||
|
|
||
| {/* On button click change image*/} | ||
| <button | ||
| className=" p-7 text-center text-cyan-800 text-lg font-bold font-['Montserrat'] underline" | ||
| onChange={handleFileChange} | ||
| > | ||
| Alterar foto de perfil | ||
| </button> | ||
| {/* Buttons for changing/deleting profile picture */} | ||
| <div className="flex gap-4 mt-2"> | ||
| <button | ||
| type="button" | ||
| onClick={imageClick} | ||
| className="p-7 text-center text-cyan-800 text-lg font-bold font-['Montserrat'] underline" | ||
| > | ||
| Alterar foto de perfil | ||
| </button> | ||
| {profilePictureUrl && ( | ||
| <button | ||
| type="button" | ||
| onClick={() => handleProfilePictureDelete()} | ||
| className="p-7 text-center text-red-500 text-lg font-bold font-['Montserrat'] underline" | ||
| > | ||
| Deletar foto | ||
| </button> | ||
| )} | ||
| </div> | ||
| <div className="grid grid-cols-2 gap-3 mt-7"> | ||
| {/* Username */} | ||
| <div className="flex flex-col "> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.