45 lines
895 B
TypeScript
45 lines
895 B
TypeScript
import { h } from 'preact';
|
|
import { useState, useEffect } from 'preact/hooks';
|
|
import { connect } from 'unistore/preact';
|
|
import axios from 'axios';
|
|
|
|
import style from './style.less';
|
|
import actions from './../actions';
|
|
import Bundle from './../components/bundle';
|
|
|
|
interface Props {
|
|
userId: string,
|
|
offers: any[],
|
|
getUserOffers: (userId: string) => void,
|
|
}
|
|
|
|
const User = ({ userId }: Props) => {
|
|
const [offers, setOffers] = useState([]);
|
|
|
|
useEffect(() => {
|
|
async function fetchOffers() {
|
|
const { data } = await axios.get(`http://localhost:41337/user/${userId}/offers`);
|
|
setOffers(data);
|
|
}
|
|
|
|
fetchOffers();
|
|
}, [userId]);
|
|
|
|
|
|
if (!offers.length) {
|
|
return (
|
|
<div class={'home'}>
|
|
loading...
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div class={'home'}>
|
|
{offers.map(Bundle)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default connect(['offers'], actions)(User);
|