Skip to content

Commit

Permalink
fix(api): clear api request and update some types
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Sep 10, 2024
1 parent e8d2da4 commit 2dfdf20
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 79 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 0 additions & 2 deletions src/api/contribution-api/getData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ const ContributionData = (url: string) => {
}
return response.json();
};

const { data, isLoading, isError, refetch } = useQuery(
[url],
fetchContributions
);

return { data, isLoading, isError, refetch };
};

Expand Down
4 changes: 2 additions & 2 deletions src/api/contribution-api/getLandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const LandingPage = (id: string) => {
return response.json();
};

const { data, error, isLoading } = useQuery(
const { data, error, isLoading } = useQuery<Publication>(
["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 };
};
Expand Down
9 changes: 5 additions & 4 deletions src/components/edit-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ const EditModal: React.FC<EditModalProps> = ({
const [filteredTags, setFilteredTags] = useState<string[]>([]);
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<Inputs>({
team: [selectedProfile],
status: "treated",
Expand All @@ -70,6 +70,7 @@ const EditModal: React.FC<EditModalProps> = ({

const fetchExistingTags = async () => {
if (!data?._id) return;
console.log(url);
try {
const response = await fetch(url, {
method: "GET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import "./styles.scss";

const ContributorRequests: React.FC<{
data: {
_id: any;
id: any;
_id: string;
id: string;
name: string;
productions: Production[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const MessagePreview = ({
return updatedList;
});
};
const formattedProductionId = data.id.replace(/\//g, "%2f");
const formattedProductionId = data._id.replace(/\//g, "%2f");

return (
<Container fluid>
Expand Down
9 changes: 3 additions & 6 deletions src/pages/contribution-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,21 @@ const ContributionPage: React.FC<ContributionPageProps> = () => {
page,
searchInMessage
);
const { data, isLoading, isError, refetch } = ContributionData(url);
let urlToSend;

if (location.pathname.includes("contributionpage")) {
urlToSend = contributionUrl;
} else if (location.pathname.includes("contact")) {
urlToSend = contactUrl;
} 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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Container className="fr-mt-10v">
Expand Down
83 changes: 22 additions & 61 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export interface Contribution {
phone: string;
tags: string[];
status: string;
responseFrom?: string;
comment?: string;
team?: string[];
type: string;
Expand All @@ -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": "[email protected]",
// "to": ["[email protected]"],
// "date": "2024-07-18",
// "body": "je veux avoir accés à l'api",
// "subject" : "demande d'acces à l'api"
// },
// {
// "message_id": "2",
// "from": "[email protected]",
// "to": ["[email protected]"],
// "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": "[email protected]",
// "to": ["[email protected]"],
// "date": "2024-07-18",
// "subject" : "RE RE - demande d'acces à l'api"
// "body": "Merci !! ",
// },
// {
// "message_id": "4",
// "from": "[email protected]",
// "to": ["[email protected]",],
// "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;
Expand All @@ -80,6 +48,7 @@ export type ContributionDataType = {
created_at: string;
status: string;
team: string[];
threads?: Thread[];
};

export type ContributionPageProps = {
Expand All @@ -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;
Expand All @@ -115,6 +82,7 @@ export type Contribute_Production = {
name: string;
status: string;
productions: any[];
threads?: Thread[];
};

export type EditModalProps = {
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit 2dfdf20

Please sign in to comment.