// components/pages/private/ProductsPage/index.jsx
import { useEffect } from 'react';
import { Page, Block, List, ListItem, Spinner } from '@cap-rel/smartcommon';
import { useApi, useStates } from '@cap-rel/smartcommon';
export const ProductsPage = () => {
const api = useApi();
const st = useStates({
initialStates: {
products: [],
loading: true,
error: null
}
});
// Chargement au montage
useEffect(() => {
loadProducts();
}, []);
const loadProducts = async () => {
st.set('loading', true);
st.set('error', null);
try {
// Requête API avec JWT automatique
const data = await api.private.get('products').json();
st.set('products', data.products);
} catch (err) {
st.set('error', err.message);
} finally {
st.set('loading', false);
}
};
// Affichage conditionnel
if (st.get('loading')) {
return ;
}
if (st.get('error')) {
return (
Erreur : {st.get('error')}
);
}
return (
{st.get('products').map(product => (
))}
);
};