Skip to content
Extraits de code Groupes Projets
Valider 82706da5 rédigé par oussama aftys's avatar oussama aftys
Parcourir les fichiers

updated the addLive service

Aucune requête de fusion associée trouvée
# HOST
NEXT_PUBLIC_HOST_API=https://api-dev-minimal-v510.vercel.app
NEXT_PUBLIC_HOST_API_URL=http://15.237.175.171:8080
NEXT_PUBLIC_WEB_SOCKET_URL=http://15.237.175.171:8080/ws
NEXT_PUBLIC_HOST_API_URL=http://localhost:8080
NEXT_PUBLIC_WEB_SOCKET_URL=http://localhost:8080/ws
NEXT_PUBLIC_HOST_API_URL=http://15.237.175.171:8080
NEXT_PUBLIC_WEB_SOCKET_URL=http://15.237.175.171:8080/ws
NEXT_PUBLIC_HOST_API_URL=http://localhost:8080
NEXT_PUBLIC_WEB_SOCKET_URL=http://localhost:8080/ws
# ASSETS
NEXT_PUBLIC_ASSETS_API=https://api-dev-minimal-v510.vercel.app
......
......@@ -43,7 +43,7 @@ export async function addLive(data: Record<string, any>, image: File) {
formData.append('image', image);
formData.append('data', new Blob([JSON.stringify(data)], { type: 'application/json' }));
const response = await axiosInstance.post(endpoints.live.create, formData, {
const response = await axiosInstance.post<ILiveItem>(endpoints.live.create, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
......
......@@ -32,13 +32,14 @@ import { addLive } from '@/shared/api/live';
import { useRouter } from 'next/navigation';
import ImageCrop from '@/components/image-crop';
import useAsync from '@/hooks/use-async';
import { add } from 'lodash';
export default function AddLiveView() {
const mdUp = useResponsive('up', 'md');
const { enqueueSnackbar } = useSnackbar();
const settings = useSettingsContext();
const router = useRouter();
const NewLiveSchema = Yup.object().shape({
title: Yup.string().required('Title is required'),
chatName: Yup.string().required('Moderator is required'),
......@@ -92,25 +93,27 @@ export default function AddLiveView() {
setProducts(products.filter((p) => p.id !== product.id));
};
const asyncAddLive = useAsync(async (formData, image) => {
await addLive(formData, image);
});
const [adding, setAdding] = useState(false);
const onSubmit = handleSubmit((data) => {
if (asyncAddLive.loading) return;
if (adding) return;
const formData = { ...data, products: products.map((product) => product.id) };
if (image) {
asyncAddLive.execute(formData, image)
.then(() => {
setAdding(true);
addLive(formData, image)
.then((response) => {
enqueueSnackbar('Live créé avec succès', { variant: 'success' });
reset();
setProducts([]);
setImage(null);
router.push(paths.dashboard.admin.live.root);
setAdding(false);
router.push(paths.dashboard.admin.live.info(response.id));
})
.catch((err) => {
enqueueSnackbar(err.message, { variant: 'error' });
console.error(err);
setAdding(false);
});
} else {
enqueueSnackbar('Veuillez ajouter une image de couverture', { variant: 'error' });
......@@ -311,7 +314,7 @@ export default function AddLiveView() {
)}
<Grid xs={12} md={8}>
<Card sx={{paddingBottom:5}}>
<Card sx={{ paddingBottom: 5 }}>
{!mdUp && <CardHeader title="Visuel" />}
<Stack spacing={2} sx={{ p: 3 }}>
<Typography variant="subtitle1">Format vidéo</Typography>
......@@ -323,9 +326,9 @@ export default function AddLiveView() {
)}
/>
</Stack>
<Stack spacing={2} sx={{ p: 3, paddingBottom:10 }}>
<Stack spacing={2} sx={{ p: 3, paddingBottom: 10 }}>
<Typography variant="subtitle1">Photo de couverture</Typography>
<ImageCrop editedImage={image} setEditedImage={setImage}/>
<ImageCrop editedImage={image} setEditedImage={setImage} />
</Stack>
</Card>
</Grid>
......@@ -340,8 +343,8 @@ export default function AddLiveView() {
type="submit"
variant="contained"
size="large"
loading={asyncAddLive.loading}
disabled={asyncAddLive.loading}
loading={adding}
disabled={adding}
sx={{ ml: 2 }}
>
Enregistrer
......
......@@ -25,7 +25,7 @@ import { useSettingsContext } from '@/shared/components/settings';
import { Container } from '@mui/material';
import { ILive, ILiveProduct, LiveStatus } from '@/shared/types/live';
import { addLive, editLive, getProductsLive } from '@/shared/api/live';
import { editLive, getProductsLive } from '@/shared/api/live';
import { useEffect, useMemo, useState } from 'react';
import { useLiveData } from '@/contexts/live-stats';
import CopyButton from '@/components/copy-button';
......
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter