-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #893 from parlemonde/ft-VIL-299/publish-dashboard
Ft vil 299/publish dashboard
- Loading branch information
Showing
45 changed files
with
1,051 additions
and
214 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+15.3 KB
.yarn/cache/@floating-ui-react-dom-npm-2.0.8-adede82f46-5da7f13a69.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-2.01 KB
.yarn/cache/@mui-core-downloads-tracker-npm-5.13.0-e6fa820f13-7919c72b85.zip
Binary file not shown.
Binary file added
BIN
+2.02 KB
.yarn/cache/@mui-core-downloads-tracker-npm-5.15.14-64629ad8a1-0a1c63d906.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+222 KB
.yarn/cache/@mui-private-theming-npm-5.15.14-da7d55aa3f-1b1ef54e82.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+8.3 KB
.yarn/cache/@types-react-transition-group-npm-4.4.10-5e11bed850-fe2ea11f70.zip
Binary file not shown.
Binary file removed
BIN
-8.48 KB
.yarn/cache/@types-react-transition-group-npm-4.4.6-3b139bdf30-0872143821.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useQuery } from 'react-query'; | ||
import type { Activity } from 'server/entities/activity'; | ||
|
||
import { axiosRequest } from 'src/utils/axiosRequest'; | ||
|
||
async function getActivities(params: { limit: number | null; isPelico: boolean; isDraft: boolean }): Promise<Activity[]> { | ||
const { limit, isPelico, isDraft } = params; | ||
return ( | ||
await axiosRequest({ | ||
method: 'GET', | ||
baseURL: '/api', | ||
url: '/activities', | ||
params: { | ||
limit, | ||
pelico: isPelico, | ||
status: isDraft ? 1 : 0, | ||
}, | ||
}) | ||
).data; | ||
} | ||
|
||
export const useGetActivities = (args: { limit: number; isPelico: boolean; isDraft: boolean }) => { | ||
const { isDraft, isPelico, limit } = args; | ||
return useQuery(['activities', limit, isPelico, isDraft], () => getActivities({ limit, isDraft, isPelico })); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useMutation } from 'react-query'; | ||
|
||
import { axiosRequest } from 'src/utils/axiosRequest'; | ||
|
||
async function publishActivity(params: { activityId: number }) { | ||
const { activityId } = params; | ||
return await axiosRequest({ | ||
method: 'PUT', | ||
baseURL: '/api', | ||
url: `/activities/${activityId}`, | ||
data: { | ||
status: 0, | ||
}, | ||
}); | ||
} | ||
|
||
export const usePublishActivity = (args: { activityId: number }) => { | ||
const { activityId } = args; | ||
return useMutation({ | ||
mutationFn: () => { | ||
return publishActivity({ activityId }); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/components/activities/ActivityCard/activity-admin/ActivityCardAdmin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useQueryClient } from 'react-query'; | ||
import type { Activity } from 'server/entities/activity'; | ||
|
||
import MoreVertIcon from '@mui/icons-material/MoreVert'; | ||
import { Card, CardHeader, Avatar, CardMedia, CardContent, Typography, Button, CardActions, CircularProgress, Menu, MenuItem } from '@mui/material'; | ||
|
||
import { usePublishActivity } from 'src/api/activities/activities.put'; | ||
import PelicoSouriant from 'src/svg/pelico/pelico-souriant.svg'; | ||
import { htmlToText } from 'src/utils'; | ||
|
||
export default function ActivityCard(activity: Pick<Activity, 'images' | 'content' | 'phase' | 'data' | 'id' | 'status'>) { | ||
const publishActivity = usePublishActivity({ activityId: activity.id }); | ||
const queryClient = useQueryClient(); | ||
const title: string = activity?.data?.title ? (activity.data.title as string) : ''; | ||
const imageUrl: string = | ||
activity?.images?.length && activity.images[0].imageUrl ? activity.images[0].imageUrl : 'https://placehold.co/600x400?text=No Picture'; | ||
const content: string = activity.content.reduce((acc, curr) => { | ||
if (curr.type === 'text') { | ||
acc += curr.value; | ||
} | ||
return acc; | ||
}, ''); | ||
|
||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); | ||
const open = Boolean(anchorEl); | ||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
useEffect(() => { | ||
if (publishActivity.isSuccess) { | ||
queryClient.invalidateQueries({ queryKey: ['activities'] }); | ||
} | ||
}, [publishActivity.isSuccess, queryClient]); | ||
return ( | ||
<Card variant="outlined" sx={{ padding: 1, margin: 2, borderRadius: 4, borderColor: '#ebebeb', width: '50%' }}> | ||
<CardHeader | ||
avatar={ | ||
<Avatar sx={{ backgroundColor: 'transparent' }}> | ||
<PelicoSouriant /> | ||
</Avatar> | ||
} | ||
title={title} | ||
titleTypographyProps={{ variant: 'h6' }} | ||
sx={{ | ||
// refer to mui content only classname | ||
'.MuiCardHeader-content': { | ||
overflow: 'hidden', | ||
whiteSpace: 'nowrap', | ||
}, | ||
}} | ||
action={ | ||
<> | ||
<Button | ||
id="basic-button" | ||
aria-controls={open ? 'basic-menu' : undefined} | ||
aria-haspopup="true" | ||
aria-expanded={open ? 'true' : undefined} | ||
onClick={handleClick} | ||
> | ||
<MoreVertIcon color="inherit" /> | ||
</Button> | ||
<Menu | ||
id="basic-menu" | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleClose} | ||
MenuListProps={{ | ||
'aria-labelledby': 'basic-button', | ||
}} | ||
> | ||
<MenuItem onClick={handleClose}>Modifier</MenuItem> | ||
<MenuItem onClick={handleClose}>Supprimer</MenuItem> | ||
</Menu> | ||
</> | ||
} | ||
/> | ||
<CardMedia | ||
sx={{ padding: '1em 1em 0 1em', objectFit: 'cover', objectPosition: 'center' }} | ||
component="img" | ||
height="194" | ||
image={imageUrl} | ||
alt="Activity picture" | ||
/> | ||
<CardContent> | ||
<Typography | ||
variant="body2" | ||
color="text.secondary" | ||
sx={{ | ||
maxHeight: '60px', | ||
overflow: 'clip', | ||
whiteSpace: 'break-spaces', | ||
}} | ||
> | ||
{htmlToText(content)} | ||
</Typography> | ||
</CardContent> | ||
{/* display publish button only if activity is not published yet (status = 1) */} | ||
{activity.status !== 0 && ( | ||
<CardActions sx={{ display: 'flex', justifyContent: 'center' }}> | ||
<Button size="small" sx={{ border: 1 }} onClick={() => publishActivity.mutate()} disabled={publishActivity.isLoading}> | ||
{publishActivity.isLoading ? <CircularProgress /> : 'Publier'} | ||
</Button> | ||
</CardActions> | ||
)} | ||
</Card> | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
src/components/activities/ActivityCard/activity-admin/ActivityCardAdminList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import type { Activity } from 'server/entities/activity'; | ||
|
||
import { Button } from '@mui/material'; | ||
import Paper from '@mui/material/Paper'; | ||
|
||
import ActivityCardAdmin from './ActivityCardAdmin'; | ||
|
||
type Props = { | ||
title: string; | ||
activities: Activity[]; | ||
svgNoData: unknown; | ||
noDataText: string; | ||
}; | ||
|
||
export default function ActivityCardAdminList({ title, activities, svgNoData, noDataText }: Props) { | ||
return ( | ||
<Paper | ||
sx={{ | ||
borderRadius: 4, | ||
}} | ||
> | ||
<div | ||
style={{ | ||
padding: 10, | ||
margin: 10, | ||
}} | ||
> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
width: '100%', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<h2>{title}</h2> | ||
<Button size="small" sx={{ border: 1, margin: 1 }}> | ||
Afficher plus | ||
</Button> | ||
</div> | ||
{activities.length ? ( | ||
<div style={{ display: 'flex' }}> | ||
{activities.map((activity) => ( | ||
<ActivityCardAdmin key={activity.id} {...activity} /> | ||
))} | ||
</div> | ||
) : ( | ||
<div | ||
style={{ | ||
paddingLeft: 20, | ||
marginTop: 30, | ||
}} | ||
> | ||
<p>{noDataText}</p> | ||
{svgNoData} | ||
</div> | ||
)} | ||
</div> | ||
</Paper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.