Skip to content

Commit

Permalink
Pass props to the elements componentnet header
Browse files Browse the repository at this point in the history
  • Loading branch information
luis committed Mar 12, 2024
1 parent 9a3b1fe commit d5bd833
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ const url = 'https://store.itmarck.com'
export const client = createDirectus(url, { globals: { fetch } })
.with(authentication('json', { storage }))
.with(rest())

export function buildImageUrl(string) {
return `${url}/assets/${string}`
}
10 changes: 6 additions & 4 deletions src/components/Header/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import './Header.css'

function Header() {
function Header(props) {
const { title, subtitle, avatar, onAvatarClick } = props
return (
<section className="Header">
<p className="Header__title">Mi cielito</p>
<p className="Header__title">{title}</p>
<div>
<p className="Header__name">Luis Barboza</p>
<p className="Header__name">{subtitle}</p>
<img
className="Header__img"
src="https://img.freepik.com/foto-gratis/collage-fondo-programacion_23-2149901782.jpg?w=996&t=st=1709668841~exp=1709669441~hmac=115e1de9393fffe964ebf0bd2fc31b12602b03077f87a6fd6306c1103629e657"
src={avatar}
alt=""
onClick={onAvatarClick}
/>
</div>
</section>
Expand Down
12 changes: 11 additions & 1 deletion src/pages/Home/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { buildImageUrl } from '../../api'
import Details from '../../components/Details'
import Dropdown from '../../components/Dropdown'
import Header from '../../components/Header'
import ProductList from '../../components/ProductList'
import Scanner from '../../components/Scanner'
import { useGlobalStore } from '../../store'
import './Home.css'
function Home() {
const store = useGlobalStore()
const { user } = store
const avatar = buildImageUrl(user?.avatar)

return (
<div className="Home">
<Header />
<Header
title="Mi cielo"
subtitle={user?.first_name + ' ' + user?.last_name}
avatar={avatar}
/>
<Dropdown />
<Scanner />
<ProductList />
Expand Down

0 comments on commit d5bd833

Please sign in to comment.