Skip to content

Commit

Permalink
Obs/cms feat update (#2682)
Browse files Browse the repository at this point in the history
* wip cms changes

* feat: add rich-text for video

* fix: review
  • Loading branch information
Datayama38 authored Dec 2, 2024
1 parent 097d6bb commit 2955a72
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 51 deletions.
8 changes: 8 additions & 0 deletions cms/src/api/article/content-types/article/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
"slug": {
"type": "uid",
"targetField": "title"
},
"buttons": {
"type": "component",
"repeatable": true,
"component": "shared.button"
},
"video": {
"type": "blocks"
}
}
}
23 changes: 16 additions & 7 deletions cms/src/api/resource/content-types/resource/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,37 @@
"mappedBy": "resources"
},
"img": {
"allowedTypes": [
"images"
],
"type": "media",
"multiple": false,
"required": true
"required": true,
"allowedTypes": [
"images"
]
},
"link": {
"type": "string"
},
"file": {
"type": "media",
"multiple": false,
"required": false,
"allowedTypes": [
"files"
],
"type": "media",
"multiple": false
]
},
"pages": {
"type": "relation",
"relation": "manyToMany",
"target": "api::page.page",
"mappedBy": "resources"
},
"buttons": {
"type": "component",
"repeatable": true,
"component": "shared.button"
},
"video": {
"type": "blocks"
}
}
}
2 changes: 2 additions & 0 deletions cms/types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ export interface ApiArticleArticle extends Schema.CollectionType {
'api::categorie.categorie'
>;
slug: Attribute.UID<'api::article.article', 'title'>;
buttons: Attribute.Component<'shared.button', true>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
publishedAt: Attribute.DateTime;
Expand Down Expand Up @@ -915,6 +916,7 @@ export interface ApiResourceResource extends Schema.CollectionType {
'manyToMany',
'api::page.page'
>;
buttons: Attribute.Component<'shared.button', true>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
publishedAt: Attribute.DateTime;
Expand Down
31 changes: 29 additions & 2 deletions public/src/app/actualites/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import MDContent from "@/components/common/MDContent";
import PageTitle from "@/components/common/PageTitle";
import Share from "@/components/common/Share";
import { Config } from "@/config";
import { fetchAPI, shorten } from "@/helpers/cms";
import { fr } from "@codegouvfr/react-dsfr";
import { ButtonProps } from '@codegouvfr/react-dsfr/Button';
import ButtonsGroup from '@codegouvfr/react-dsfr/ButtonsGroup';
import Tag from "@codegouvfr/react-dsfr/Tag";
import Image from 'next/image';
import { fetchAPI, shorten } from "@/helpers/cms";
import MDContent from "@/components/common/MDContent";
import { Button } from '../../../interfaces/cms/collectionsInterface';

export async function generateMetadata({ params }: { params: { slug: string }}) {
const query = {
Expand Down Expand Up @@ -123,6 +126,30 @@ export default async function ActuSingle({ params }: { params: { slug: string }}
</div>
</div>
}
{
data.attributes.buttons &&
<ButtonsGroup
alignment={'right'}
inlineLayoutWhen={'always'}
buttons={data.attributes.buttons.map((b:Button) => {
return {
children:b.title,
linkProps: b.url.startsWith('http') ? {
href: b.url,
title:`${b.title} - nouvelle fenêtre` ,
"aria-label":`${b.title} - nouvelle fenêtre`,
target:'_blank',
rel: "noopener noreferrer"
} : {
href: b.url,
},
iconId: b.icon ?? '',
priority: b.color ?? 'primary',
}
}) as [ButtonProps, ...ButtonProps[]]}
buttonsIconPosition={'right'}
/>
}
</div>
</article>
);
Expand Down
47 changes: 29 additions & 18 deletions public/src/app/ressources/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import MDContent from "@/components/common/MDContent";
import PageTitle from "@/components/common/PageTitle";
import Share from "@/components/common/Share";
import { Config } from "@/config";
import { fetchAPI, shorten } from "@/helpers/cms";
import { fr } from "@codegouvfr/react-dsfr";
import { ButtonProps } from "@codegouvfr/react-dsfr/Button";
import ButtonsGroup from '@codegouvfr/react-dsfr/ButtonsGroup';
import Tag from "@codegouvfr/react-dsfr/Tag";
import Image from 'next/image';
import { fetchAPI, shorten } from "@/helpers/cms";
import MDContent from "@/components/common/MDContent";
import { Button } from "@codegouvfr/react-dsfr/Button";
import { Button } from '../../../interfaces/cms/collectionsInterface';

export async function generateMetadata({ params }: { params: { slug: string }}) {
const query = {
Expand Down Expand Up @@ -120,28 +122,37 @@ export default async function ResourceSingle({ params }: { params: { slug: strin
<div>
<MDContent source={data.attributes.content} />
</div>
{data.attributes.link &&
<Button
linkProps={data.attributes.link.startsWith('http') ? {
href: data.attributes.link,
title:`En savoir plus - nouvelle fenêtre` ,
"aria-label":`En savoir plus - nouvelle fenêtre`,
target:'_blank'
}: {
href: data.attributes.link,
}
}
>
En savoir plus
</Button>
{
data.attributes.buttons &&
<ButtonsGroup
alignment={'right'}
inlineLayoutWhen={'always'}
buttons={data.attributes.buttons.map((b:Button) => {
return {
children:b.title,
linkProps: b.url.startsWith('http') ? {
href: b.url,
title:`${b.title} - nouvelle fenêtre` ,
"aria-label":`${b.title} - nouvelle fenêtre`,
target:'_blank',
rel: "noopener noreferrer"
} : {
href: b.url,
},
iconId: b.icon ?? '',
priority: b.color ?? 'primary',
}
}) as [ButtonProps, ...ButtonProps[]]}
buttonsIconPosition={'right'}
/>
}
{data.attributes.file.data &&
<div className={fr.cx('fr-card','fr-enlarge-link', 'fr-card--download')} style={{height:'8em'}}>
<div className={fr.cx('fr-card__body')}>
<div className={fr.cx('fr-card__content')}>
<div className={fr.cx('fr-card__title')}>
<a download href={data.attributes.file.data.attributes.url}>
{`Télécharger la ressource${data.attributes.file.data.attributes.name}`}
{`Télécharger la ressource: ${data.attributes.file.data.attributes.name}`}
</a>
</div>
<div className={fr.cx('fr-card__end')}>
Expand Down
31 changes: 17 additions & 14 deletions public/src/interfaces/actualites/componentsInterface.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Button } from "../cms/collectionsInterface";

export interface ActuCardProps {
title: string,
content: string,
date: string,
img: string,
img_legend?: string,
href: string,
horizontal?: false | undefined,
categories: CategorieProps[]
title: string;
content: string;
date: string;
img: string;
img_legend?: string;
href: string;
horizontal?: false | undefined;
categories: CategorieProps[];
buttons?: Button[];
}

export interface CategorieProps {
id: string | number,
attributes:{
label: string,
slug: string,
}
}
id: string | number;
attributes: {
label: string;
slug: string;
};
}
23 changes: 13 additions & 10 deletions public/src/interfaces/ressources/componentsInterface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
export interface RessourceCardProps {
title: string,
content: string,
date: string,
img: string,
href:string,
link?: string,
file?: string,
horizontal?: false | undefined
}
import { Button } from "../cms/collectionsInterface";

export interface RessourceCardProps {
title: string;
content: string;
date: string;
img: string;
href: string;
link?: string;
file?: string;
horizontal?: false;
buttons?: Button[];
}

0 comments on commit 2955a72

Please sign in to comment.