You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
import type { NextPage } from 'next';
|
|
import React from 'react';
|
|
import { useSelector } from 'react-redux'
|
|
import { MainLayout } from '../layouts/Customer';
|
|
import { CardStock, SkeletonStock, BoxScroll } from '../components';
|
|
import { useAppDispatch } from '../redux/store';
|
|
import { fetchStoke } from '../redux/stoke/stock';
|
|
import { selectStokeData } from '../redux/stoke/selectors';
|
|
|
|
const Home: NextPage = () => {
|
|
const dispatch = useAppDispatch();
|
|
|
|
React.useEffect(() => {
|
|
dispatch(
|
|
fetchStoke(),
|
|
);
|
|
}, [1]);
|
|
|
|
const { items, status } = useSelector(selectStokeData);
|
|
|
|
const stokes = items.map((obj, index) => <CardStock key={index} {...obj} />);
|
|
const skeletons = [...new Array(4)].map((_, index) => <SkeletonStock key={index} />);
|
|
|
|
return (
|
|
<MainLayout>
|
|
<BoxScroll>
|
|
{status === 'loading' ? skeletons : stokes}
|
|
</BoxScroll>
|
|
</MainLayout>
|
|
)
|
|
}
|
|
|
|
export async function getServerSideProps({ req, res }) {
|
|
// await dbConnect();
|
|
// const user = await getUser(req, res);
|
|
if (!user) {
|
|
return {
|
|
redirect: {
|
|
permanent: false,
|
|
destination: "/signin",
|
|
},
|
|
props: {},
|
|
};
|
|
}
|
|
return {
|
|
props: {
|
|
user,
|
|
},
|
|
};
|
|
}
|
|
|
|
export default Home
|
|
|