Added frontend to show every profile picture from the Profile Pictures list

This commit is contained in:
Lucas Oliveira 2024-06-07 15:34:12 -03:00
commit 9478c14f57
4 changed files with 57 additions and 12 deletions

View file

@ -8,6 +8,7 @@ import {
APITemplateType, APITemplateType,
Component, Component,
LoginType, LoginType,
ProfilePicturesTypeAPI,
Users, Users,
VertexBuildTypeAPI, VertexBuildTypeAPI,
VerticesOrderTypeAPI, VerticesOrderTypeAPI,
@ -364,6 +365,10 @@ export async function uploadFile(
return await api.post(`${BASE_URL_API}files/upload/${id}`, formData); return await api.post(`${BASE_URL_API}files/upload/${id}`, formData);
} }
export async function getProfilePictures(): Promise<ProfilePicturesTypeAPI> {
return await api.get(`${BASE_URL_API}files/list/profile_pictures`);
}
export async function postCustomComponent( export async function postCustomComponent(
code: string, code: string,
apiClass: APIClassType, apiClass: APIClassType,

View file

@ -1,8 +1,11 @@
import { PROFILE_PICTURES_GET_ERROR_ALERT } from "../../../../../../../../../constants/alerts_constants"; import { PROFILE_PICTURES_GET_ERROR_ALERT } from "../../../../../../../../../constants/alerts_constants";
import { getProfilePictures } from "../../../../../../../../../controllers/API";
const useGetProfilePictures = (setErrorData) => { const useGetProfilePictures = (setErrorData) => {
const handleGetProfilePictures = async () => { const handleGetProfilePictures = async () => {
try { try {
const profilePictures = await getProfilePictures();
return profilePictures.files;
} catch (error) { } catch (error) {
setErrorData({ setErrorData({
title: PROFILE_PICTURES_GET_ERROR_ALERT, title: PROFILE_PICTURES_GET_ERROR_ALERT,

View file

@ -1,25 +1,58 @@
import { useEffect, useState } from "react";
import useAlertStore from "../../../../../../../../stores/alertStore"; import useAlertStore from "../../../../../../../../stores/alertStore";
import { gradients } from "../../../../../../../../utils/styleUtils"; import { gradients } from "../../../../../../../../utils/styleUtils";
import useGetProfilePictures from "./hooks/use-get-profile-pictures"; import useGetProfilePictures from "./hooks/use-get-profile-pictures";
import { Label } from "../../../../../../../../components/ui/label";
import {
BACKEND_URL,
BASE_URL_API,
} from "../../../../../../../../constants/constants";
export default function ProfilePictureChooserComponent({ value, onChange }) { export default function ProfilePictureChooserComponent({ value, onChange }) {
const setErrorData = useAlertStore((state) => state.setErrorData); const setErrorData = useAlertStore((state) => state.setErrorData);
const getProfilePictures = useGetProfilePictures({ setErrorData }); const getProfilePictures = useGetProfilePictures({ setErrorData });
const [profilePictures, setProfilePictures] = useState<string[][]>([]);
useEffect(() => {
getProfilePictures().then((data) => {
if (data) {
data.forEach((profile_picture) => {
const [folder, path] = profile_picture.split("/");
setProfilePictures((prev) => {
if (prev[folder]) {
prev[folder].push(path);
} else {
prev[folder] = [path];
}
return prev;
});
});
}
});
});
return ( return (
<div className="flex flex-wrap items-center justify-start gap-2"> <div className="flex flex-wrap items-center justify-start gap-2">
{gradients.map((gradient, idx) => ( {profilePictures.map((folder, idx) => (
<div <Label>
onClick={() => { <div className="edit-flow-arrangement">
onChange(gradient); <span className="font-medium">{folder}</span>
}} </div>
className={ <div className="flex flex-wrap items-center justify-start gap-2">
"duration-400 h-12 w-12 cursor-pointer rounded-full transition-all " + {folder.map((path, idx) => (
gradient + <img
(value === gradient ? " shadow-lg ring-2 ring-primary" : "") key={idx}
} src={`${BACKEND_URL.slice(
key={idx} 0,
></div> BACKEND_URL.length - 1,
)}${BASE_URL_API}files/images/${folder + "/" + path}`}
className="h-12 w-12 rounded-full"
onClick={() => onChange(folder + "/" + path)}
/>
))}
</div>
</Label>
))} ))}
</div> </div>
); );

View file

@ -93,6 +93,10 @@ export type UploadFileTypeAPI = {
flowId: string; flowId: string;
}; };
export type ProfilePicturesTypeAPI = {
files: string[];
};
export type LoginType = { export type LoginType = {
grant_type?: string; grant_type?: string;
username: string; username: string;