diff --git a/src/app/[locale]/applications/page.tsx b/src/app/[locale]/applications/page.tsx index 437aff0..ba3ff15 100644 --- a/src/app/[locale]/applications/page.tsx +++ b/src/app/[locale]/applications/page.tsx @@ -31,6 +31,9 @@ export default function ApplcnPage({ const currentPage = Number(searchParams?.page) || 1; const t = useTranslations(); + const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc"); + const [sortedColumn, setSortedColumn] = useState(null); + useEffect(() => { const fetchData = async () => { try { @@ -58,6 +61,42 @@ export default function ApplcnPage({ router.push(`?page=${page}`); }; + function getTransformedStatus(status: string) { + if (status === "active" || status === "inprogress") { + return "Applied"; + } + return toTitleCase(status); + } + const sortApplications = (column: string) => { + const order = column === sortedColumn && sortOrder === "asc" ? "desc" : "asc"; + const sortedApplications = [...applications].sort((a, b) => { + if (column === "program_name") { + return order === "asc" + ? a.program_name.localeCompare(b.program_name) + : b.program_name.localeCompare(a.program_name); + } else if (column === "application_status") { + return order === "asc" + ? getTransformedStatus(a.application_status).localeCompare( + getTransformedStatus(b.application_status) + ) + : getTransformedStatus(b.application_status).localeCompare( + getTransformedStatus(a.application_status) + ); + } else if (column === "application_id") { + return order === "asc" ? a.application_id - b.application_id : b.application_id - a.application_id; + } else if (column === "date_applied") { + const dateA = new Date(a.date_applied).getTime(); + const dateB = new Date(b.date_applied).getTime(); + return order === "asc" ? dateA - dateB : dateB - dateA; + } + return 0; + }); + + setApplications(sortedApplications); + setSortOrder(order); + setSortedColumn(column); + }; + const isDataEmpty = !Array.isArray(applications) || applications.length < 1 || !applications; function getStatusClass(status: string) { @@ -116,7 +155,10 @@ export default function ApplcnPage({ {t("No_")} -
+
sortApplications("program_name")} + > {t("Program Name")} -
+
sortApplications("application_status")} + > {t("Application Status")} -
+
sortApplications("application_id")} + > {t("Application ID")} -
+
sortApplications("date_applied")} + > {t("Date Applied")} ("asc"); + const [sortedColumn, setSortedColumn] = useState(null); + useEffect(() => { const fetchData = async () => { try { @@ -58,6 +61,34 @@ export default function BenefPage({ router.push(`?page=${page}`); }; + const sortBenefits = (column: string) => { + const order = column === sortedColumn && sortOrder === "asc" ? "desc" : "asc"; + const sortedBenefits = [...benefits].sort((a, b) => { + if (column === "program_name") { + return order === "asc" + ? a.program_name.localeCompare(b.program_name) + : b.program_name.localeCompare(a.program_name); + } else if (column === "entitlement_reference_number") { + return order === "asc" + ? a.entitlement_reference_number - b.entitlement_reference_number + : b.entitlement_reference_number - a.entitlement_reference_number; + } else if (column === "funds_awaited") { + return order === "asc" ? a.funds_awaited - b.funds_awaited : b.funds_awaited - a.funds_awaited; + } else if (column === "funds_received") { + return order === "asc" ? a.funds_received - b.funds_received : b.funds_received - a.funds_received; + } else if (column === "date_approved") { + const dateA = new Date(a.date_approved).getDate(); + const dateB = new Date(b.date_approved).getDate(); + return order === "asc" ? dateA - dateB : dateB - dateA; + } + return 0; + }); + + setBenefits(sortedBenefits); + setSortOrder(order); + setSortedColumn(column); + }; + const isDataEmpty = !Array.isArray(benefits) || benefits.length < 1 || !benefits; return ( @@ -96,7 +127,10 @@ export default function BenefPage({ {t("No_")} -
+
sortBenefits("program_name")} + > {t("Program Name")} -
+
sortBenefits("entitlement_reference_number")} + > {t("Entitlement Reference Number")} -
+
sortBenefits("funds_awaited")} + > {t("Funds Awaited")} -
+
sortBenefits("funds_received")} + > {t("Funds Received")} -
+
sortBenefits("date_approved")} + > {t("Date Approved")} ([]); const [totalPages, setTotalPages] = useState(0); const currentPage = Number(searchParams?.page) || 1; + + const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc"); + const [sortedColumn, setSortedColumn] = useState(null); + const t = useTranslations(); useEffect(() => { @@ -54,6 +58,34 @@ export default function Page({ setPaginatedPrograms(programs.slice(start, end)); }, [currentPage, programs]); + const sortPrograms = (column: string) => { + const order = column === sortedColumn && sortOrder === "asc" ? "desc" : "asc"; + const sortedPrograms = [...programs].sort((a, b) => { + if (column === "program_name") { + return order === "asc" + ? a.program_name.localeCompare(b.program_name) + : b.program_name.localeCompare(a.program_name); + } else if (column === "enrollment_status") { + return order === "asc" + ? a.enrollment_status.localeCompare(b.enrollment_status) + : b.enrollment_status.localeCompare(a.enrollment_status); + } else if (column === "total_funds_awaited") { + return order === "asc" + ? a.total_funds_awaited - b.total_funds_awaited + : b.total_funds_awaited - a.total_funds_awaited; + } else if (column === "total_funds_received") { + return order === "asc" + ? a.total_funds_received - b.total_funds_received + : b.total_funds_received - a.total_funds_received; + } + return 0; + }); + + setPrograms(sortedPrograms); + setSortOrder(order); + setSortedColumn(column); + }; + const handlePageChange = (page: number) => { router.push(`?page=${page}`); }; @@ -96,7 +128,10 @@ export default function Page({ {t("No_")} -
+
sortPrograms("program_name")} + > {t("Program Name")} -
+
sortPrograms("enrollment_status")} + > {t("Enrollment Status")} -
+
sortPrograms("total_funds_awaited")} + > {t("Total Funds Awaited")} -
+
sortPrograms("total_funds_received")} + > {t("Total Funds Received")} ("asc"); + const [sortedColumn, setSortedColumn] = useState(null); + useEffect(() => { const fetchData = async () => { try { @@ -70,6 +73,21 @@ export default function ProgrmPage({ setPaginatedPrograms(programs.slice(start, end)); }, [currentPage, programs]); + const sortPrograms = (column: string) => { + const order = column === sortedColumn && sortOrder === "asc" ? "desc" : "asc"; + const sortedPrograms = [...programs].sort((a, b) => { + if (column === "name") { + return order === "asc" ? a.name.localeCompare(b.name) : b.name.localeCompare(a.name); + } else if (column === "program_status") + return order === "asc" ? a.state.localeCompare(b.state) : b.state.localeCompare(a.state); + return 0; + }); + + setPrograms(sortedPrograms); + setSortOrder(order); + setSortedColumn(column); + }; + const handlePageChange = (page: number) => { router.push(`?page=${page}`); }; @@ -310,7 +328,10 @@ export default function ProgrmPage({ {t("No_")} -
+
sortPrograms("name")} + > {t("Program Name")} -
+
sortPrograms("program_status")} + > {t("Program Status")} - {toTitleCase(application.application_status)} + {application.application_status === "active" || + application.application_status === "inprogress" + ? "Applied" + : toTitleCase(application.application_status)} {application.application_id} diff --git a/src/app/[locale]/submission/page.tsx b/src/app/[locale]/submission/page.tsx index ada875a..ee424ff 100644 --- a/src/app/[locale]/submission/page.tsx +++ b/src/app/[locale]/submission/page.tsx @@ -5,8 +5,8 @@ import {useSearchParams} from "next/navigation"; import {useLocale, useTranslations} from "next-intl"; import {useEffect, useState} from "react"; import {AuthUtil} from "@/components/auth"; -import {ApplicationDetails} from "@/types"; -import {fetchApplicationDetails, fetchPrograms} from "@/utils"; +import {ApplicationDetails, Profile} from "@/types"; +import {fetchApplicationDetails, fetchPrograms, fetchProfile} from "@/utils"; import {prefixBasePath} from "@/utils/path"; export default function Submitted() { @@ -15,11 +15,25 @@ export default function Submitted() { const [isToastVisible, setIsToastVisible] = useState(true); const [applicationDetails, setApplicationDetails] = useState(null); + const [profile, setProfile] = useState(null); const searchParams = useSearchParams(); const programId = searchParams.get("programId"); const t = useTranslations(); + useEffect(() => { + const fetchUserData = async () => { + try { + const userProfile = await fetchProfile(); + setProfile(userProfile); + } catch (error) { + console.error("Error fetching user profile:", error); + } + }; + + fetchUserData(); + }, []); + useEffect(() => { const fetchData = async () => { try { @@ -91,7 +105,9 @@ export default function Submitted() {
-

Dear User,

+

+ Dear {profile?.given_name} {profile?.family_name}, +

Thank you for submitting your form for the program {applicationDetails.program_name}. Your application number is {applicationDetails.application_id}. @@ -126,7 +142,10 @@ export default function Submitted() {

{applicationDetails.program_name}


diff --git a/src/app/[locale]/view/page.tsx b/src/app/[locale]/view/page.tsx index 05625bf..733403f 100644 --- a/src/app/[locale]/view/page.tsx +++ b/src/app/[locale]/view/page.tsx @@ -27,6 +27,9 @@ export default function ApplcnPage() { const [totalPages, setTotalPages] = useState(0); const [currentPage, setCurrentPage] = useState(1); + const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc"); + const [sortedColumn, setSortedColumn] = useState(null); + const t = useTranslations(); useEffect(() => { const fetchData = async () => { @@ -85,6 +88,42 @@ export default function ApplcnPage() { }); } + function getTransformedStatus(status: string) { + if (status === "active" || status === "inprogress") { + return "Applied"; + } + return toTitleCase(status); + } + const sortApplications = (column: string) => { + const order = column === sortedColumn && sortOrder === "asc" ? "desc" : "asc"; + const sortedApplications = [...applications].sort((a, b) => { + if (column === "program_name") { + return order === "asc" + ? a.program_name.localeCompare(b.program_name) + : b.program_name.localeCompare(a.program_name); + } else if (column === "application_status") { + return order === "asc" + ? getTransformedStatus(a.application_status).localeCompare( + getTransformedStatus(b.application_status) + ) + : getTransformedStatus(b.application_status).localeCompare( + getTransformedStatus(a.application_status) + ); + } else if (column === "application_id") { + return order === "asc" ? a.application_id - b.application_id : b.application_id - a.application_id; + } else if (column === "date_applied") { + const dateA = new Date(a.date_applied).getTime(); + const dateB = new Date(b.date_applied).getTime(); + return order === "asc" ? dateA - dateB : dateB - dateA; + } + return 0; + }); + + setApplications(sortedApplications); + setSortOrder(order); + setSortedColumn(column); + }; + return (
{isLoading ? ( @@ -121,7 +160,10 @@ export default function ApplcnPage() { {t("No_")} -
+
sortApplications("program_name")} + > {t("Program Name")} -
+
sortApplications("application_status")} + > {t("Application Status")} -
+
sortApplications("application_id")} + > {t("Application ID")} -
+
sortApplications("date_applied")} + > {t("Date Applied")}