From 2dfdf20860d08bdf5a130254fde85b00218b1a03 Mon Sep 17 00:00:00 2001 From: Mihoub Date: Tue, 10 Sep 2024 10:36:57 +0200 Subject: [PATCH] fix(api): clear api request and update some types --- .github/workflows/staging.yml | 4 + src/api/contribution-api/getData.tsx | 2 - src/api/contribution-api/getLandingPage.tsx | 4 +- src/components/edit-modal/index.tsx | 9 +- .../contributor-requests.tsx | 4 +- .../link-publications/message-preview.tsx | 2 +- src/pages/contribution-page/index.tsx | 9 +- src/pages/home/index.tsx | 2 +- src/types/index.ts | 83 +++++-------------- 9 files changed, 40 insertions(+), 79 deletions(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 43d6091..7b77c5d 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -65,3 +65,7 @@ jobs: mattermost_webhook_url: ${{ secrets.MATTERMOST_WEBHOOK_URL }} mattermost_channel: ${{ env.MM_NOTIFICATION_CHANNEL}} deployment_url: ${{ env.DEPLOYMENT_URL }} + - name: 🎉 Celebrate Success in Mattermost + if: success() + run: | + curl -X POST -H 'Content-Type: application/json' -d '{"text": "🎉 Woohoo! Le déploiement est *green* et tout fonctionne bien! C\'est l\'heure de faire la fête! 🥳🍾"}' ${{ secrets.MATTERMOST_WEBHOOK_URL }} diff --git a/src/api/contribution-api/getData.tsx b/src/api/contribution-api/getData.tsx index 6816f0a..29e6c4c 100644 --- a/src/api/contribution-api/getData.tsx +++ b/src/api/contribution-api/getData.tsx @@ -11,12 +11,10 @@ const ContributionData = (url: string) => { } return response.json(); }; - const { data, isLoading, isError, refetch } = useQuery( [url], fetchContributions ); - return { data, isLoading, isError, refetch }; }; diff --git a/src/api/contribution-api/getLandingPage.tsx b/src/api/contribution-api/getLandingPage.tsx index c408f14..4b627d5 100644 --- a/src/api/contribution-api/getLandingPage.tsx +++ b/src/api/contribution-api/getLandingPage.tsx @@ -25,12 +25,12 @@ const LandingPage = (id: string) => { return response.json(); }; - const { data, error, isLoading } = useQuery( + const { data, error, isLoading } = useQuery( ["contributions", id], fetchContributions ); - const landingPage = data?.hits?.hits?.[0]?._source.landingPage; + const landingPage = (data as any)?.hits?.hits?.[0]?._source.landingPage; return { landingPage, isLoading, error }; }; diff --git a/src/components/edit-modal/index.tsx b/src/components/edit-modal/index.tsx index 9a93799..03915f0 100644 --- a/src/components/edit-modal/index.tsx +++ b/src/components/edit-modal/index.tsx @@ -31,20 +31,20 @@ const EditModal: React.FC = ({ const [filteredTags, setFilteredTags] = useState([]); const [tagInput, setTagInput] = useState(""); const [showTagModal, setShowTagModal] = useState(false); - const [currentStatus, setCurrentStatus] = useState("treated"); // Ajouter l'état pour le statut actuel + const [currentStatus, setCurrentStatus] = useState("treated"); let basePath = "contact"; if (window.location.pathname.includes("contributionpage")) { basePath = "contribute"; } else if (window.location.pathname.includes("apioperations")) { - basePath = "contribute_productions"; + basePath = "production"; } const isDevelopment = import.meta.env.VITE_HEADER_TAG === "Development"; const url = isDevelopment - ? `https://scanr-api.dataesr.ovh/${basePath}/${data?._id}` - : `${window.location.origin}/api/${basePath}/${data?._id}`; + ? `http://localhost:3000/api/${basePath}/${data?._id}` + : `https://ticket-office-api.staging.dataesr.ovh/api/${basePath}/${data?._id}`; const [inputs, setInputs] = useState({ team: [selectedProfile], status: "treated", @@ -70,6 +70,7 @@ const EditModal: React.FC = ({ const fetchExistingTags = async () => { if (!data?._id) return; + console.log(url); try { const response = await fetch(url, { method: "GET", diff --git a/src/pages/api-operation-page/link-publications/contributor-requests.tsx b/src/pages/api-operation-page/link-publications/contributor-requests.tsx index dd21d43..942316d 100644 --- a/src/pages/api-operation-page/link-publications/contributor-requests.tsx +++ b/src/pages/api-operation-page/link-publications/contributor-requests.tsx @@ -9,8 +9,8 @@ import "./styles.scss"; const ContributorRequests: React.FC<{ data: { - _id: any; - id: any; + _id: string; + id: string; name: string; productions: Production[]; }; diff --git a/src/pages/api-operation-page/link-publications/message-preview.tsx b/src/pages/api-operation-page/link-publications/message-preview.tsx index 75c938f..2e31eb0 100644 --- a/src/pages/api-operation-page/link-publications/message-preview.tsx +++ b/src/pages/api-operation-page/link-publications/message-preview.tsx @@ -92,7 +92,7 @@ const MessagePreview = ({ return updatedList; }); }; - const formattedProductionId = data.id.replace(/\//g, "%2f"); + const formattedProductionId = data._id.replace(/\//g, "%2f"); return ( diff --git a/src/pages/contribution-page/index.tsx b/src/pages/contribution-page/index.tsx index 22db805..b1d55d1 100644 --- a/src/pages/contribution-page/index.tsx +++ b/src/pages/contribution-page/index.tsx @@ -59,9 +59,7 @@ const ContributionPage: React.FC = () => { page, searchInMessage ); - const { data, isLoading, isError, refetch } = ContributionData(url); let urlToSend; - if (location.pathname.includes("contributionpage")) { urlToSend = contributionUrl; } else if (location.pathname.includes("contact")) { @@ -69,14 +67,13 @@ const ContributionPage: React.FC = () => { } else { urlToSend = ""; } + const { data, isLoading, isError, refetch } = ContributionData(url); const getTags = ContributionData(urlToSend); - const allTags = getTags?.data?.data?.map((tag) => tag?.tags); + const allTags = getTags?.data?.map((tag) => tag?.tags); const meta = (data as { meta: any })?.meta; const maxPage = meta ? Math.ceil(meta.total / 10) : 1; - const contributions: Contribution[] = (data as { data: Contribution[] }) - ?.data; - + const contributions: Contribution[] = data; useEffect(() => { if (contributions && contributions.length > 0) { setSelectedContribution((prevSelectedContribution) => { diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 7423162..616ba27 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -18,7 +18,7 @@ const Home = () => { const [filter, setFilter] = useState("contributions"); const url = filter === "object" ? contributionUrl : contactUrl; const { data, isLoading, isError } = ContributionData(url); - const contributions = (data as { data: [] })?.data; + const contributions = data as { data: [] }; return ( diff --git a/src/types/index.ts b/src/types/index.ts index f414ca3..35c37f6 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,7 +6,6 @@ export interface Contribution { phone: string; tags: string[]; status: string; - responseFrom?: string; comment?: string; team?: string[]; type: string; @@ -15,53 +14,22 @@ export interface Contribution { organisation?: string; fonction?: string; modified_at?: string; - mailSentDate?: string; - mailSent?: string; + threads?: Thread[]; } -// { -// "thread": [ -// { -// "messages": [ -// { -// "message_id": "1", -// "from": "contributor@example.com", -// "to": ["scanr@recherche.......com"], -// "date": "2024-07-18", -// "body": "je veux avoir accés à l'api", -// "subject" : "demande d'acces à l'api" -// }, -// { -// "message_id": "2", -// "from": "scanr@example.com", -// "to": ["contributor@example.com"], -// "date": "2024-07-18", -// "team": "mihoub", -// "subject" : "RE - demande d'acces à l'api" -// "body": "Voici vos ids pour acces à scanr API", -// "repliesTo": message_id = 1 -// }, -// { -// "message_id": "3", -// "from": "contributor@example.com", -// "to": ["scanr@example.com"], -// "date": "2024-07-18", -// "subject" : "RE RE - demande d'acces à l'api" -// "body": "Merci !! ", -// }, -// { -// "message_id": "4", -// "from": "scanr@exemple.com", -// "to": ["contributor@example.com",], -// "date": "2024-07-18", -// "team": "mihoub", -// "body": "De rien!", -// "subject" : "RE RE RE - demande d'acces à l'api" -// "repliesTo": message_id = 3 -// } -// ] -// ] -// } +export interface Thread { + team: [string]; + responseMessage: string; + threadId: string; + responses?: Response[]; + timestamp: string; +} + +export interface Response { + responseMessage: string; + timestamp: string; + team?: string[]; +} export type ContributionDataType = { responseFrom: string; @@ -80,6 +48,7 @@ export type ContributionDataType = { created_at: string; status: string; team: string[]; + threads?: Thread[]; }; export type ContributionPageProps = { @@ -95,11 +64,9 @@ export type MessagePreviewProps = { }; export type Contribute_Production = { - fullName: any; - firstName: any; - lastName: any; - mailSentDate: string | number | Date; - mailSent: string; + fullName: string; + firstName: string; + lastName: string; responseByMail: string; responseFrom: string; tag: string; @@ -115,6 +82,7 @@ export type Contribute_Production = { name: string; status: string; productions: any[]; + threads?: Thread[]; }; export type EditModalProps = { @@ -159,23 +127,16 @@ export interface PersonInfo { export type Publication = { hits: number; landingPage?: string; - // id: string; - // isOa: boolean; - // type: string; - // year: number; }; export type MailData = { + name: string; _id: string; - mailSent?: string; - mailSentDate?: string; - responseFrom?: string; - name?: string; - refetch?: () => void; + threads?: Thread[]; }; export type LatestMailsProps = { - data: { data: MailData[] }; + data: MailData[]; refetch?: () => void; };