Skip to content

Commit

Permalink
hotfix VIL-596
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-pages committed Oct 22, 2024
1 parent 52c6156 commit 4cb4aa7
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 30 deletions.
14 changes: 6 additions & 8 deletions server/controllers/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ activityController.get({ path: '/mascotte', userType: UserType.OBSERVATOR }, asy
});

activityController.get({ path: '/admin/draft' }, async (req, res) => {
// const adminUsers = await AppDataSource.getRepository(User)
// .createQueryBuilder('User')
// .select('User.id')
// .where('user.type IN (:...type)', { type: 0 })
// .getMany();
const adminUsers = await AppDataSource.query(`
SELECT user.id
FROM user
Expand All @@ -132,7 +127,7 @@ activityController.get({ path: '/admin/draft' }, async (req, res) => {
const draftActivities = await AppDataSource.getRepository(Activity)
.createQueryBuilder('Activity')
.where('Activity.status = :status', { status: req.query.status ? Number(getQueryString(req.query.status)) || 0 : undefined })
.andWhere('Activity.userId IN (:...userIds)', { userIds: adminUsers.map((u) => u.id) })
.andWhere('Activity.userId IN (:...userIds)', { userIds: adminUsers.map((u: { id: number }) => u.id) })
.orderBy('Activity.updateDate', 'DESC')
.limit(req.query.limit ? Number(getQueryString(req.query.limit)) || 200 : undefined)
.getMany();
Expand All @@ -143,7 +138,7 @@ activityController.get({ path: '/admin/draft' }, async (req, res) => {
.createQueryBuilder('Activity')
.where('Activity.status = :status', { status: req.query.status ? Number(getQueryString(req.query.status)) || 0 : undefined })
.andWhere('Activity.isDisplayed = :isDisplayed', { isDisplayed: req.query.isDisplayed ? req.query.isDisplayed === 'true' : false })
.andWhere('Activity.userId IN (:...userIds)', { userIds: adminUsers.map((u) => u.id) })
.andWhere('Activity.userId IN (:...userIds)', { userIds: adminUsers.map((u: { id: number }) => u.id) })
.orderBy('Activity.updateDate', 'DESC')
.limit(req.query.limit ? Number(getQueryString(req.query.limit)) || 200 : undefined)
.getMany();
Expand Down Expand Up @@ -296,7 +291,10 @@ activityController.post(
await AppDataSource.getRepository(Activity).save(activity);
}

await AppDataSource.getRepository(Activity).update({ id: data.activityParentId }, { status: ActivityStatus.PUBLISHED, isDisplayed: false });
await AppDataSource.getRepository(Activity).update(
{ id: data.activityParentId },
{ status: ActivityStatus.PUBLISHED, isDisplayed: false, publishDate: new Date() },
);

res.sendJSON({ message: 'Votre publication a été publiée' });
} catch (error) {
Expand Down
14 changes: 7 additions & 7 deletions src/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ export const Navigation = (): JSX.Element => {
phase: 2,
disabled: isParent,
},
{
label: 'Créer une énigme',
path: '/creer-une-enigme',
icon: <KeyIcon style={{ fill: 'currentcolor' }} width="1.4rem" />,
phase: 2,
disabled: isParent,
},
{
label: 'Lancer un défi',
path: '/lancer-un-defi',
Expand All @@ -172,13 +179,6 @@ export const Navigation = (): JSX.Element => {
phase: 2,
disabled: isParent,
},
{
label: 'Créer une énigme',
path: '/creer-une-enigme',
icon: <KeyIcon style={{ fill: 'currentcolor' }} width="1.4rem" />,
phase: 2,
disabled: isParent,
},
{
label: 'Poser une question',
path: '/poser-une-question/1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MoreVertIcon from '@mui/icons-material/MoreVert';
import { Card, CardHeader, Avatar, CardMedia, CardContent, Typography, Button, CardActions, Menu, MenuItem } from '@mui/material';

import { deleteActivity } from 'src/api/activities/activities.admin.delete';
import { useGetChildrenActivitiesById } from 'src/api/activities/activities.adminGetChildren';
import { usePublishActivity } from 'src/api/activities/activities.put';
import PelicoSouriant from 'src/svg/pelico/pelico-souriant.svg';
import { htmlToText } from 'src/utils';
Expand All @@ -20,6 +21,17 @@ export default function ActivityCard({
modifiedDisabled?: boolean;
}) {
const publishActivity = usePublishActivity({ activityId: activity.id });
const howManyChildren = useGetChildrenActivitiesById({ id: Number(activity.id) });
// eslint-disable-next-line
// @ts-ignore
const publishDate = new Date(activity.publishDate);
const formattedDate = new Intl.DateTimeFormat('fr-FR', {
year: '2-digit',
month: '2-digit',
day: '2-digit',
}).format(publishDate);

const subtitle = `Publié le ${formattedDate} dans ${howManyChildren.data?.length} Village-Monde`;
const queryClient = useQueryClient();
const router = useRouter();
const title: string = activity?.data?.title ? (activity.data.title as string) : '';
Expand Down Expand Up @@ -69,6 +81,7 @@ export default function ActivityCard({
</Avatar>
}
title={title}
subheader={activity.status === 0 ? subtitle : ''}
titleTypographyProps={{ variant: 'h6' }}
sx={{
// refer to mui content only classname
Expand Down Expand Up @@ -125,13 +138,22 @@ export default function ActivityCard({
{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' }}>
<Link href={`/admin/newportal/publier/prepublish/${activity.id}`}>
<Button size="small" sx={{ border: 1, marginRight: 1 }}>
Publier
</Button>
{/* eslint-disable-next-line */}
{/* @ts-ignore */}
{activity.data.title.length === 0 || activity.data.resume.length === 0 ? (
// eslint-disable-next-line
// @ts-ignore
<Button disabled="true" size="small" sx={{ border: 1, marginRight: 1 }}>
Publier
</Button>
) : (
<Button size="small" sx={{ border: 1, marginRight: 1 }}>
Publier
</Button>
)}
</Link>
</CardActions>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/newportal/contenulibre/success/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FreeContentSuccess = () => {
<div style={{ width: '100%', padding: '1rem 1rem 1rem 1rem' }}>
<div style={{ width: '100%', maxWidth: '20rem', margin: '4rem auto', backgroundColor: bgPage, padding: '1rem', borderRadius: '10px' }}>
<p className="text" style={{ textAlign: 'center' }}>
La publication a été crée ! Rendez-vous dans l’espace de publication pour la rendre visible aux classes
La publication a été créée ! Rendez-vous dans l’espace de publication pour la rendre visible aux classes
</p>
<PelicoSouriant style={{ width: '60%', height: 'auto', margin: '0 20%' }} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/newportal/publier/draft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const AllDraft = () => {
<h1 style={{ marginLeft: 10 }}>Activités non publiées</h1>
</div>
</Link>
<div style={{ width: isMobile ? '100%' : '40%' }}>
<div style={{ width: isMobile ? '100%' : '40%', marginTop: 20 }}>
<SearchField setter={(e) => setSearch(e.currentTarget.value)} />
</div>
<AllActivitiesAdmin activities={data} search={search} />
Expand Down
3 changes: 0 additions & 3 deletions src/pages/admin/newportal/publier/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ const Publier = () => {
const { user } = React.useContext(UserContext);
const draftActivities = useGetActivitiesAdminDraft({ limit: 2, isDraft: true });
const publishedActivities = useGetActivitiesAdminDraft({ limit: 2, isDraft: false, isDisplayed: false });
console.log('draftActivities = ', draftActivities);
console.log('publishedActivities = ', publishedActivities);
console.log('User = ', user);

const router = useRouter();

Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/newportal/publier/prepublish/edit/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const ModifPrepublish = () => {

if (villagesToAdd.length > 0) {
await postAdminActivity({ activityParentId: Number(id), phase: Number(selectedPhase), villages: villagesToAdd });
enqueueSnackbar('Nouvelles activités créées avec succès', { variant: 'success' });
enqueueSnackbar('Activités publiées avec succès', { variant: 'success' });
}

if (villagesToDelete.length > 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/pages/admin/newportal/publier/published/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { useGetActivitiesAdminDraft } from 'src/api/activities/activities.admin.
import { useGetVillages } from 'src/api/villages/villages.get';
import SearchField from 'src/components/SearchField';
import type { Option } from 'src/components/accueil/Filters/FilterSelect';
import { FilterSelect } from 'src/components/accueil/Filters/FilterSelect';
// import { FilterSelect } from 'src/components/accueil/Filters/FilterSelect';
import AllActivitiesAdmin from 'src/components/activities/ActivityCard/activity-admin/AllActivitiesAdmin';
import BackArrow from 'src/svg/back-arrow.svg';

const Published = () => {
const [search, setSearch] = useState('');
const [selectedVillage, setSelectedVillage] = useState<Option<number> | null>(null);
const [selectedVillage] = useState<Option<number> | null>(null);
const { data, isError, isIdle, isLoading } = useGetActivitiesAdminDraft({ limit: null, isDraft: false, isDisplayed: false });
const villages = useGetVillages();
function filterActivitiesByVillage(selectedVillage: Option<number> | null, activities: Activity[]) {
Expand All @@ -39,7 +39,7 @@ const Published = () => {
}}
>
<div>
<FilterSelect
{/* <FilterSelect
name="Village - Monde"
onChange={(e: Option<number>) => setSelectedVillage(e)}
options={villages.data.reduce<Array<Option<number>>>((acc, village, i) => {
Expand All @@ -50,9 +50,9 @@ const Published = () => {
return acc;
}, [])}
value={selectedVillage ? selectedVillage.key : 0}
/>
/> */}
</div>
<div style={{ width: '40%' }}>
<div style={{ width: '40%', marginTop: 20 }}>
<SearchField setter={(e) => setSearch(e.currentTarget.value)} />
</div>
</div>
Expand Down

0 comments on commit 4cb4aa7

Please sign in to comment.