Skip to content

Commit

Permalink
feat: show user mailing-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
moroine committed Jul 22, 2024
1 parent ef4e81d commit cb1b3d8
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 41 deletions.
15 changes: 15 additions & 0 deletions server/src/modules/server/admin/upload.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
updateDocument,
uploadFile,
} from "../../actions/documents.actions";
import { findMailingListWithDocument } from "../../actions/mailingLists.actions";
import { Server } from "../server";

const validateFile = (file: MultipartFile) => {
Expand Down Expand Up @@ -130,6 +131,20 @@ export const uploadAdminRoutes = ({ server }: { server: Server }) => {
return response.status(200).send(documents.map(toPublicDocument));
}
);
server.get(
"/admin/mailing-list/:user_id",
{
schema: zRoutes.get["/admin/mailing-list/:user_id"],
onRequest: [server.auth(zRoutes.get["/admin/mailing-list/:user_id"])],
},
async (request, response) => {
const mailingLists = await findMailingListWithDocument({
added_by: request.params.user_id.toString(),
});

return response.status(200).send(mailingLists);
}
);

server.delete(
"/admin/document/:id",
Expand Down
18 changes: 0 additions & 18 deletions shared/helpers/openapi/__snapshots__/generateOpenapi.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
},
"schemas": {
"Error": {
"additionalProperties": false,
"properties": {
"code": {
"type": [
Expand Down Expand Up @@ -158,11 +157,9 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"schema": {
"anyOf": [
{
"additionalProperties": false,
"description": "Organisation deca Response body",
"properties": {
"contrats": {
"additionalProperties": false,
"properties": {
"appr": {
"type": "number",
Expand All @@ -182,7 +179,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
"dernier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -197,7 +193,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
],
},
"premier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -218,7 +213,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
{
"additionalProperties": false,
"properties": {
"code": {
"type": [
Expand Down Expand Up @@ -324,7 +318,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"description": "Organisation deca Request body",
"properties": {
"siret": {
Expand All @@ -350,11 +343,9 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"schema": {
"anyOf": [
{
"additionalProperties": false,
"description": "Organisation deca Response body",
"properties": {
"contrats": {
"additionalProperties": false,
"properties": {
"appr": {
"type": "number",
Expand All @@ -374,7 +365,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
"dernier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -389,7 +379,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
],
},
"premier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -410,7 +399,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
{
"additionalProperties": false,
"properties": {
"code": {
"type": [
Expand Down Expand Up @@ -520,7 +508,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"description": "Organisation validation Request body",
"properties": {
"email": {
Expand Down Expand Up @@ -551,11 +538,9 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"schema": {
"anyOf": [
{
"additionalProperties": false,
"description": "Organisation deca Response body",
"properties": {
"contrats": {
"additionalProperties": false,
"properties": {
"appr": {
"type": "number",
Expand All @@ -575,7 +560,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
"dernier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -590,7 +574,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
],
},
"premier_contrat": {
"additionalProperties": false,
"properties": {
"date_debut_contrat": {
"type": "string",
Expand All @@ -611,7 +594,6 @@ exports[`generateOpenApiSchema > should generate proper schema 1`] = `
"type": "object",
},
{
"additionalProperties": false,
"properties": {
"code": {
"type": [
Expand Down
25 changes: 18 additions & 7 deletions shared/routes/upload.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from "zod";

import { zObjectId } from "../models/common";
import { ZUploadDocumentPublic } from "../models/document.model";
import { ZMailingListWithDocument } from "../models/mailingList.model";
import { IRoutesDef } from "./common.routes";

export const zUploadRoutes = {
Expand All @@ -18,6 +19,19 @@ export const zUploadRoutes = {
ressources: {},
},
},
"/admin/mailing-list/:user_id": {
method: "get",
path: "/admin/mailing-list/:user_id",
params: z.object({ user_id: zObjectId }),
response: {
"200": z.array(ZMailingListWithDocument),
},
securityScheme: {
auth: "cookie-session",
access: "admin",
ressources: {},
},
},
"/admin/documents/types": {
method: "get",
path: "/admin/documents/types",
Expand All @@ -35,13 +49,10 @@ export const zUploadRoutes = {
"/admin/upload": {
method: "post",
path: "/admin/upload",
querystring: z
.object({
type_document: z.string(),
import_content: z.string().optional(),
delimiter: z.string(),
})
,
querystring: z.object({
type_document: z.string(),
delimiter: z.string(),
}),
body: z.unknown(),
response: {
"200": ZUploadDocumentPublic,
Expand Down
16 changes: 2 additions & 14 deletions ui/app/admin/fichier/import/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { IGetRoutes, IPostRoutes, IResponse } from "shared";
import ToggleSwitchInput from "../../../../components/form/ToggleSwitchInput";
import Toast, { useToast } from "../../../../components/toast/Toast";
import { apiGet, apiPost } from "../../../../utils/api.utils";
import { queryClient } from "../../../../utils/query.utils";
import Breadcrumb, { PAGES } from "../../../components/breadcrumb/Breadcrumb";

interface FormValues extends Zod.input<IPostRoutes["/admin/upload"]["querystring"]> {
file: FileList;
should_import_content: boolean;
has_new_type_document: boolean;
new_type_document: string;
delimiter_other: string;
Expand Down Expand Up @@ -54,7 +54,6 @@ const AdminImportPage = () => {
} = useForm<FormValues>({
defaultValues: {
type_document: "",
should_import_content: true,
has_new_type_document: false,
},
});
Expand All @@ -68,7 +67,6 @@ const AdminImportPage = () => {
type_document,
has_new_type_document,
new_type_document,
should_import_content,
delimiter,
delimiter_other,
}) => {
Expand All @@ -81,7 +79,6 @@ const AdminImportPage = () => {
querystring: {
type_document: has_new_type_document ? new_type_document : type_document,
delimiter: askDelimiterOther ? delimiter_other : delimiter,
...(should_import_content && { import_content: "true" }),
},
body: formData,
});
Expand All @@ -101,6 +98,7 @@ const AdminImportPage = () => {
console.error(error);
} finally {
setIsSubmitting(false);
queryClient.invalidateQueries({ queryKey: ["/admin/documents"] });
}
};

Expand Down Expand Up @@ -152,16 +150,6 @@ const AdminImportPage = () => {
}}
/>
)}
<ToggleSwitchInput
control={control}
{...register("should_import_content")}
toggleSwitchProps={{
showCheckedHint: false,
disabled: isSubmitting,
label: "Importer le contenu",
inputTitle: "Importer le contenu",
}}
/>

<Box mb={2}>
<DSFRUpload
Expand Down
4 changes: 2 additions & 2 deletions ui/app/admin/fichier/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const AdminImportPage = () => {
const [isDeleting, setIsDeleting] = useState(false);

const { data: documentLists, refetch } = useQuery<IUploadDocumentJson[]>({
queryKey: ["documentLists"],
queryKey: ["/admin/documents"],
queryFn: async () => apiGet("/admin/documents", {}),
refetchInterval: 1000,
refetchInterval: 15_000,
});

const onDeleteDocument = async () => {
Expand Down
11 changes: 11 additions & 0 deletions ui/app/admin/utilisateurs/[id]/components/UserView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ const UserView: FC<Props> = ({ user }) => {
},
}}
/>

<Button
iconId="fr-icon-arrow-right-line"
iconPosition="right"
linkProps={{
href: PAGES.adminListeDiffusion(user._id).path,
}}
priority="tertiary"
>
Listes de diffusion
</Button>
</>
);
};
Expand Down
33 changes: 33 additions & 0 deletions ui/app/admin/utilisateurs/[id]/liste-diffusion/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";

import { Box, Typography } from "@mui/material";
import { useQuery } from "@tanstack/react-query";
import { IMailingListWithDocumentJson } from "shared/models/mailingList.model";

import { apiGet } from "../../../../../utils/api.utils";
import Breadcrumb, { PAGES } from "../../../../components/breadcrumb/Breadcrumb";
import ListMailingList from "../../../../liste-diffusion/components/ListMailingList";

interface Props {
params: { id: string };
}

const AdminImportPage = ({ params }: Props) => {
const { data: mailingLists, refetch } = useQuery<IMailingListWithDocumentJson[]>({
queryKey: ["/admin/mailing-list/:user_id", { user_id: params.id }],
queryFn: async () => apiGet("/admin/mailing-list/:user_id", { params: { user_id: params.id } }),
});

return (
<>
<Breadcrumb pages={[PAGES.adminUsers(), PAGES.adminUserView(params.id), PAGES.adminListeDiffusion(params.id)]} />
<Box display="flex" flexDirection="row">
<Typography flexGrow={1} variant="h2">
{PAGES.adminListeDiffusion(params.id).title}
</Typography>
</Box>
<ListMailingList mailingLists={mailingLists} onDelete={refetch} />
</>
);
};
export default AdminImportPage;
4 changes: 4 additions & 0 deletions ui/app/components/breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const PAGES = {
title: "Gestion des fichiers",
path: "/admin/fichier",
}),
adminListeDiffusion: (id: string) => ({
title: "Gestion des listes de diffusion",
path: `/admin/utilisateurs/${id}/liste-diffusion`,
}),
adminImport: () => ({
title: "Import de fichier",
path: "/admin/fichier/import",
Expand Down

0 comments on commit cb1b3d8

Please sign in to comment.