Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
MaGOs92 committed Jan 4, 2024
1 parent f593e84 commit b672dc1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 51 deletions.
2 changes: 1 addition & 1 deletion components/events/event-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const newEventForm = {
startHour: "",
endHour: "",
isOnlineOnly: true,
adresse: {},
address: {},
isSubscriptionClosed: false,
instructions: "",
tags: [],
Expand Down
95 changes: 52 additions & 43 deletions pages/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,42 @@ const EventsPage = ({ incommingEvents, pastEvents }: EventsPageProps) => {
{`Évènement${incommingEvents.length > 1 ? "s" : ""} à venir`}
</>
),
content:
incommingEvents.length === 0 ? (
"Aucun évènement à venir"
) : (
<EditableList
headers={["Type", "Nom", "Date", "Horaires", ""]}
caption="Liste des évènements"
data={incommingEvents}
filter={{
placeholder: "Filtrer par nom",
property: "name",
}}
createBtn={
<div className="fr-grid-row fr-grid-row--gutters fr-grid-row--right">
<div className="fr-col-2">
<Button
onClick={() => massImportEventsModale.open()}
iconId="fr-icon-add-line"
>
Import en masse
content: (
<EditableList
headers={["Type", "Nom", "Date", "Horaires", ""]}
caption="Liste des évènements"
data={incommingEvents}
filter={{
placeholder: "Filtrer par nom",
property: "name",
}}
createBtn={
<div className="fr-grid-row fr-grid-row--gutters fr-grid-row--right">
<div className="fr-col-2">
<Button
onClick={() => massImportEventsModale.open()}
iconId="fr-icon-add-line"
>
Import en masse
</Button>
</div>
<div className="fr-col-2">
<Link
passHref
href={{
pathname: "/events/new",
}}
>
<Button iconId="fr-icon-add-line">
Créer un évènement
</Button>
</div>
<div className="fr-col-2">
<Link
passHref
href={{
pathname: "/events/new",
}}
>
<Button iconId="fr-icon-add-line">
Créer un évènement
</Button>
</Link>
</div>
</Link>
</div>
}
renderItem={EventItem}
/>
),
</div>
}
renderItem={EventItem}
/>
),
},
{
label: (
Expand Down Expand Up @@ -151,14 +148,26 @@ export async function getServerSideProps() {
const events = await getEvents();

const incommingEvents =
events.filter((event) => {
return new Date(event.date) > new Date();
}) || [];
events
.filter((event) => {
return new Date(event.date) > new Date();
})
.sort((eventA, eventB) => {
return (
new Date(eventA.date).getTime() - new Date(eventB.date).getTime()
);
}) || [];

const pastEvents =
events.filter((event) => {
return new Date(event.date) < new Date();
}) || [];
events
.filter((event) => {
return new Date(event.date) < new Date();
})
.sort((eventA, eventB) => {
return (
new Date(eventB.date).getTime() - new Date(eventA.date).getTime()
);
}) || [];

return {
props: {
Expand Down
2 changes: 1 addition & 1 deletion pages/events/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const NewEventPage = () => {
try {
const newEvent = await createEvent(formData);
toast("Evènement créé", { type: "success" });
await router.push(`/events/${newEvent._id}`);
await router.push("/events");
} catch (error: unknown) {
console.log(error);
toast("Erreur lors de la création de l'évènement", { type: "error" });
Expand Down
2 changes: 1 addition & 1 deletion server/lib/events/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const createSchema = {
date: {valid: validDate, isRequired: true, type: 'string'},
tags: {isRequired: true, type: 'array'},
isOnlineOnly: {isRequired: true, type: 'boolean'},
address: {isRequired: false, type: 'object'},
address: {isRequired: true, type: 'object'},
href: {isRequired: false, type: 'string'},
isSubscriptionClosed: {isRequired: true, type: 'boolean'},
instructions: {isRequired: false, type: 'string'},
Expand Down
10 changes: 5 additions & 5 deletions types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export type EventType = {
tags: EventTypeTagEnum[];
isOnlineOnly: boolean;
address?: {
nom: string;
numero: string;
voie: string;
codePostal: string;
commune: string;
nom?: string;
numero?: string;
voie?: string;
codePostal?: string;
commune?: string;
};
href?: string;
isSubscriptionClosed: boolean;
Expand Down

0 comments on commit b672dc1

Please sign in to comment.