Skip to content

Commit

Permalink
fix: photo and title
Browse files Browse the repository at this point in the history
  • Loading branch information
ialexanderbrito committed Mar 31, 2022
1 parent d129c48 commit bb45291
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/components/CardBarbeiro/CardBarbeiro.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
align-items: center;
justify-content: space-between;
flex-direction: column;
}

h2 {
margin-top: 0px;
}
.title {
font-weight: bold;
color: var(--white);
}
33 changes: 31 additions & 2 deletions src/components/CardBarbeiro/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { useEffect, useState } from 'react';

import { UserMetadata } from 'types/IContext';

import { getPhoto } from 'services/get/photo';

import styles from './CardBarbeiro.module.scss';

type Props = {
Expand All @@ -8,13 +12,38 @@ type Props = {
};

export function CardBarbeiro({ barbeiro, onClick }: Props) {
const [photo, setPhoto] = useState('');
const [name, setName] = useState('');

async function getPhotoUser(id: string) {
const { data, error, status } = await getPhoto(id);

if (error) {
switch (status) {
default:
throw new Error('Erro ao buscar informações do usuário');
}
}

if (!data) return;

setPhoto(data[0].j[0].src);
setName(data[0].j[0].name);
}

useEffect(() => {
if (barbeiro) {
getPhotoUser(barbeiro.id);
}
}, [barbeiro]);

return (
<div className={styles.card} onClick={onClick} key={barbeiro?.id}>
<div className={styles.containerImg}>
<img src={barbeiro?.avatar_url || barbeiro?.picture} alt={barbeiro?.nome} />
<img src={photo || barbeiro?.avatar_url || barbeiro?.picture} alt={barbeiro?.nome} />
</div>
<div className={styles.containerInfo}>
<h2>{barbeiro?.nome}</h2>
<h2 className={styles.title}>{name || barbeiro?.nome}</h2>
<strong>aaa</strong>
<strong>aaa</strong>
</div>
Expand Down

0 comments on commit bb45291

Please sign in to comment.