Skip to content

Commit

Permalink
Merge pull request #162 from Vizzuality/fix/project-fields
Browse files Browse the repository at this point in the history
Fix/project fields
  • Loading branch information
mluena authored Oct 23, 2024
2 parents 74746d0 + 2f2befe commit 050012c
Show file tree
Hide file tree
Showing 14 changed files with 3,896 additions and 2,976 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
uploadCollaboratorEditSuggestionsCsv,
} from "@/services/collaborators";
import { uploadOtherToolsCsv, uploadToolEditSuggestionCsv } from "@/services/other-tools";
import { toast } from "react-toastify";

export default function CSVImport({
valueType,
Expand Down
4 changes: 2 additions & 2 deletions client/src/containers/collaborators/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ export default function CollaboratorForm() {
}),
link: z.string().refine(
(value) => {
// Allow URLs starting with "www." or valid URLs starting with "http" or "https"
return /^(https?:\/\/)?(www\.)?[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(\/[^\s]*)?$/.test(value);
// This regex requires the URL to start with either http://, https://, or www.
return /^(https?:\/\/|www\.)[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(\/[^\s]*)?$/.test(value);
},
{ message: "Please enter a valid URL" },
),
Expand Down
8 changes: 7 additions & 1 deletion client/src/containers/other-tools/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ export default function ToolForm() {

const formSchema = z.object({
name: z.string().min(1, { message: "Please enter tool name" }),
link: z.string().url({ message: "Please enter a valid URL" }),
link: z.string().refine(
(value) => {
// This regex requires the URL to start with either http://, https://, or www.
return /^(https?:\/\/|www\.)[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(\/[^\s]*)?$/.test(value);
},
{ message: "Please enter a valid URL" },
),
category: z
.number()
.optional()
Expand Down
16 changes: 8 additions & 8 deletions client/src/containers/projects/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,17 @@ export default function ProjectForm() {
message: "Please select a sdg",
}),
),
status: z.string().min(1, {
status: z.coerce.number().min(1, {
message: "Please enter status",
}),
funding: z.coerce.number().min(1, {
message: "Please select type of funding",
}),
organization_type: z.string().min(1, {
organization_type: z.coerce.number().min(1, {
message: "Please enter organization type",
}),
source_country: z.string().min(1, { message: "Please select a country" }),
objective: z.string().min(1, { message: "Please enter objective" }),
source_country: z.coerce.number().min(1, { message: "Please select a country" }),
objective: z.coerce.number().min(1, { message: "Please enter objective" }),
});

// TO - DO - add category from edit when API gets fixed
Expand All @@ -330,11 +330,11 @@ export default function ProjectForm() {
countries:
previousData?.countries?.data?.map(({ id }: { id?: number }) => id as number) || [],
sdgs: previousData?.sdgs?.data?.map(({ id }: { id?: number }) => id as number) || [],
status: previousData?.status || "",
status: previousData?.status?.data?.id as number,
funding: previousData?.funding?.data?.id as number,
organization_type: previousData?.organization_type || "",
source_country: previousData?.source_country || "",
objective: previousData?.objective as string,
organization_type: previousData?.organization_type?.data?.id as number,
source_country: previousData?.source_country?.data?.id as number,
objective: previousData?.objective?.data?.id as number,
},
}),
});
Expand Down
79 changes: 69 additions & 10 deletions client/src/containers/projects/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ const ProjectPopup = () => {
countries: {
fields: ["name"],
},
project_status: true,
project_type_of_funding: true,
status: {
fields: ["name"],
},
funding: {
fields: ["name"],
},
},
},
{
Expand All @@ -39,6 +43,12 @@ const ProjectPopup = () => {
const pillar = data?.data?.attributes?.pillar;
const sdgs = data?.data?.attributes?.sdgs;
const countries = data?.data?.attributes?.countries;
const projectStatus = data?.data?.attributes?.status?.data?.attributes?.name;
const projectTypeOfFunding = data?.data?.attributes?.funding?.data?.attributes?.name;
const organizationType = data?.data?.attributes?.organization_type?.data?.attributes?.name;
const sourceCountry = data?.data?.attributes?.source_country?.data?.attributes?.name;
const objective = data?.data?.attributes?.objective?.data?.attributes?.name;
const info = data?.data?.attributes?.info;

const { format } = Intl.NumberFormat("en-US", {
style: "currency",
Expand Down Expand Up @@ -79,14 +89,6 @@ const ProjectPopup = () => {
</div>
)}

{/* ACCOUNT */}
{!!data?.data?.attributes?.account && (
<div className="space-y-2.5">
<h3 className="text-xxs uppercase text-gray-500">Account</h3>
<div className="text-sm">{data?.data?.attributes?.account}</div>
</div>
)}

{/* AMOUNT */}
{!!data?.data?.attributes?.amount && (
<div className="space-y-2.5">
Expand All @@ -110,6 +112,7 @@ const ProjectPopup = () => {
</div>
</div>
)}

{/* SDGS */}
{!!sdgs?.data?.length && (
<div className="space-y-2.5">
Expand All @@ -127,6 +130,62 @@ const ProjectPopup = () => {
</ul>
</div>
)}

{/* ACCOUNT */}
{!!data?.data?.attributes?.account && (
<div className="space-y-2.5">
<h3 className="text-xxs uppercase text-gray-500">Account</h3>
<div className="text-sm">{data?.data?.attributes?.account}</div>
</div>
)}

{/* STATUS */}
{!!projectStatus && (
<div className="space-y-2.5">
<h3 className="text-xxs uppercase text-gray-500">Status</h3>
<div className="text-sm">{projectStatus}</div>
</div>
)}

{/* Source Country */}
{!!sourceCountry && (
<div className="space-y-2.5">
<h3 className="text-xxs uppercase text-gray-500">Source Country</h3>
<div className="text-sm">{sourceCountry}</div>
</div>
)}

{/* Organization Type */}
{!!organizationType && (
<div className="space-y-2.5">
<h3 className="text-xxs uppercase text-gray-500">Organization Type</h3>
<div className="text-sm">{organizationType}</div>
</div>
)}

{/* INFO */}
{!!info && (
<div className="space-y-2.5">
<h3 className="text-xxs uppercase text-gray-500">Info</h3>
<div className="text-sm">{info}</div>
</div>
)}

{/* Objective */}
{!!objective && (
<div className="space-y-2.5">
<h3 className="text-xxs uppercase text-gray-500">Objective</h3>
<div className="text-sm">{objective}</div>
</div>
)}

{/* TYPE OF FUNDING */}
{!!projectTypeOfFunding && (
<div className="space-y-2.5">
<h3 className="text-xxs uppercase text-gray-500">Type of funding</h3>
<div className="text-sm">{projectTypeOfFunding}</div>
</div>
)}
</section>
</div>
</Popup>
Expand Down
10 changes: 6 additions & 4 deletions client/src/services/collaborators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ export function uploadCollaboratorsCsv(
},
...options,
})
.then(({ data }) => {
console.info("Collaborators uploaded successfully:", data);
.then((response) => {
console.info("Collaborators uploaded successfully:", response.data);
toast.success("Collaborators uploaded successfully");
return response;
})
.catch((err) => {
toast.error(err.response.data.error.message);
Expand All @@ -82,9 +83,10 @@ export function uploadCollaboratorEditSuggestionsCsv(
},
...options,
})
.then(({ data }) => {
console.info("Collaborators suggestions uploaded successfully:", data);
.then((response) => {
console.info("Collaborators suggestions uploaded successfully:", response.data);
toast.success("Collaborators suggestions uploaded successfully");
return response;
})
.catch((err) => {
toast.error(err.response.data.error.message);
Expand Down
10 changes: 6 additions & 4 deletions client/src/services/other-tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export function uploadOtherToolsCsv(
},
...options,
})
.then(({ data }) => {
console.info("Tools uploaded successfully:", data);
.then((response) => {
console.info("Tools uploaded successfully:", response.data);
toast.success("Tools uploaded successfully");
return response;
})
.catch((err) => {
toast.error(err.response.data.error.message);
Expand All @@ -83,9 +84,10 @@ export function uploadToolEditSuggestionCsv(
},
...options,
})
.then(({ data }) => {
console.info("Tools suggestions uploaded successfully:", data);
.then((response) => {
console.info("Tools suggestions uploaded successfully:", response.data);
toast.success("Tools suggestions uploaded successfully");
return response;
})
.catch((err) => {
toast.error(err.response.data.error.message);
Expand Down
5 changes: 3 additions & 2 deletions client/src/services/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ export function uploadProjectsSuggestionCsv(
},
...options,
})
.then(({ data }) => {
console.info("Projects suggestions uploaded successfully:", data);
.then((response) => {
console.info("Projects suggestions uploaded successfully:", response.data);
toast.success("Projects suggestions uploaded successfully");
return response;
})
.catch((err) => {
toast.error(err.response.data.error.message);
Expand Down
Loading

0 comments on commit 050012c

Please sign in to comment.