Skip to content

Commit

Permalink
feat: add companies page and added poc tables
Browse files Browse the repository at this point in the history
  • Loading branch information
RupaakSrinivas committed Jun 6, 2024
1 parent e94fb06 commit 35fd0a4
Show file tree
Hide file tree
Showing 16 changed files with 886 additions and 336 deletions.
172 changes: 172 additions & 0 deletions src/app/(dashboard)/companies/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
"use client";

import { authStore } from "@/store/auth";
import { fetchAllCompanies } from "@/utils/organisation";

import { Table, ScrollArea, Text, Modal } from "@mantine/core";
import { useState, useEffect } from "react";
import { organisationStore } from "@/store/organisation";
import { IoMdAddCircleOutline } from "react-icons/io";
import { useDisclosure } from "@mantine/hooks";
import Link from "next/link";
import ModifyCompany from "@/components/CompanyForm";
import { toast, ToastContainer } from "react-toastify";
import { useLinkStore } from "@/store/crumbs";

interface RowData {
comp_id: number;
name: string;
website: string;
industry: string;
linkedin: string;
}

export default function Home({ params }: Readonly<{ params: { id: number } }>) {
const { accessToken } = authStore();
const { org } = organisationStore();
const [sponsors, setSponsors] = useState<RowData[]>([]);
const [company, setCompany] = useState<RowData>({
comp_id: 0,
name: "",
website: "",
industry: "",
linkedin: "",
});
const event_id = String(params.id);
const [opened, { open, close }] = useDisclosure(false);
const { setLink } = useLinkStore();

const handleOpen = (data: RowData) => {
setCompany(data);
open();
};

const handleCloseFunc = (success?: boolean, data?: string) => {
if (success) {
toast.success(data);
} else {
toast.error(data);
}
fetchSponsors();
close();
};

const handleClose = () => {
fetchSponsors();
close();
};

const fetchSponsors = async () => {
try {
const data = await fetchAllCompanies(accessToken, org.id);
const rowData = data.map((company, _key) => {
return {
comp_id: company.id,
name: company.name,
website: company.website,
industry: company.industry,
linkedin: company.linkedin,
};
});
setSponsors(rowData);
setLink([
{ href: "/team", title: "My Team" },
{ href: `/team/${event_id}/companies`, title: "Companies" },
]);
} catch (error: any) {
console.error(error);
}
};

useEffect(() => {
if (org.id !== 0) fetchSponsors();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const rows = sponsors.map((row) => (
<Table.Tr
key={row.comp_id}
onClick={() => {
console.log(row.comp_id);
handleOpen(row);
}}
className=" border-b cursor-pointer hover:bg-[#6c6c6c66] rounded-md"
>
<Table.Td>{row.name}</Table.Td>
<Table.Td className="text-center">{row.website}</Table.Td>
<Table.Td className="text-center">{row.industry}</Table.Td>
<Table.Td className="text-center">{row.linkedin}</Table.Td>
</Table.Tr>
));

return (
<>
<ToastContainer />
<div className="h-full absolute max-w-full overflow-x-auto bg-white rounded-md gap-8 flex flex-col items-center p-4">
<div className="text-center gap-4 flex flex-col">
<h1 className="text-3xl font-bold">View and Manage all Companies</h1>
<p className="text-gray-500 text-sm w-full max-w-[400px] text-center">
View and Update the Details of the Companies that is added under the organisation
</p>
</div>
<Table.ScrollContainer
type="native"
minWidth={500}
maw={"100%"}
mah={"70%"}
>
<ScrollArea className="">
<Table
horizontalSpacing="md"
verticalSpacing="xs"
miw={500}
layout="fixed"
striped
>
<Table.Tbody>
<Table.Tr bg={"white"}>
<Table.Th>Company Name</Table.Th>
<Table.Th className="text-center">Website</Table.Th>
<Table.Th className="text-center">Industry</Table.Th>
<Table.Th className="text-center">Linkedin</Table.Th>
</Table.Tr>
</Table.Tbody>
<Table.Tbody className="">
{rows.length > 0 ? (
rows
) : (
<Table.Tr>
<Table.Td colSpan={4}>
<Text fw={500} ta="center">
Nothing found
</Text>
</Table.Td>
</Table.Tr>
)}
</Table.Tbody>
</Table>
<Modal
classNames={{ content: "border-2 border-red-500", root: "" }}
opened={opened}
centered
size="auto"
onClose={handleClose}
title="Modify Company Details"
w={"100%"}
>
<ModifyCompany close={handleCloseFunc} company={company} />
</Modal>
</ScrollArea>
</Table.ScrollContainer>
{/* <div className={`w-full flex flex-row items-center justify-center`}>
<Link
href={`/companies/createNew`}
className="flex bg-white flex-row sticky bottom-0 items-center gap-2 border-2 font-bold rounded-sm border-blue-500 text-blue-500 p-2 px-4 z-10"
>
<IoMdAddCircleOutline className="text-2xl font-bold" /> Add new Company
</Link>
</div> */}
</div>
</>
);
}
5 changes: 5 additions & 0 deletions src/app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ function Dashboard({
icon: BiBuildings,
label: "Sponsorships",
},
{
link: "/companies",
icon: BiBuildings,
label: "Companies",
},
]
: []
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(dashboard)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function Profile() {
);
setSponsors(resp);
} catch (error: any) {
toast.error(error.response.data);
toast.error(error.message);
}
}
fetchData();
Expand Down
8 changes: 1 addition & 7 deletions src/app/(dashboard)/sponsorships/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ export default function Home() {
<Table.Td className="text-center">{row.added_by}</Table.Td>
<Table.Td className="text-center">
<p
className={`
${row.status === "Accepted" ? "bg-[#cef6e1] text-[#3AB876]" : ""}
${row.status === "Rejected" ? "bg-[#fedcd4] text-[#F46E47]" : ""}
${row.status === "No Reply" ? "bg-[#fff3cf] text-[#ffca11]" : ""}
${row.status === "In Progress" ? "bg-[#D1C5FF] text-[#7F5DFF]" : ""}
${row.status === "Not Contacted" ? "bg-[#d4d5d5] text-[#414141]" : ""}
py-2 rounded-full w-[10rem] m-auto`}
className={`${row.status} py-2 rounded-full w-[10rem] m-auto`}
>
{row.status}
</p>
Expand Down
23 changes: 12 additions & 11 deletions src/app/(dashboard)/team/[id]/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@ export default function Home({ params }: Readonly<{ params: { id: number } }>) {
<Table.Td>{row.company_name}</Table.Td>
<Table.Td className="text-center">{row.user_name}</Table.Td>
<Table.Td className="text-center">
<p
className={`
${row.status === "No Reply" ? "bg-[#cef6e1] text-[#3AB876]" : ""}
${row.status === "Accepted" ? "bg-[#fedcd4] text-[#F46E47]" : ""}
${row.status === "Rejected" ? "bg-[#fff3cf] text-[#ffca11]" : ""}
${row.status === "In Progress" ? "bg-[#D1C5FF] text-[#7F5DFF]" : ""}
${row.status === "Not Contacted" ? "bg-[#d4d5d5] text-[#414141]" : ""}
py-2 rounded-full w-[10rem] m-auto`}
<p
className={`${row.status} py-2 rounded-full w-[10rem] m-auto`}
>
{row.status}
</p>
Expand All @@ -61,21 +55,28 @@ export default function Home({ params }: Readonly<{ params: { id: number } }>) {
return (
<div className="flex flex-row h-full overflow-x-auto absolute gap-4 w-full rounded-md">
<div className="flex w-full h-full flex-col gap-4">
<div className="bg-gradient-to-r from-[#4d4d4d] to-[#3e3e3e] h-full w-full justify-between flex rounded-md flex-col gap-4 md:flex-row p-4 text-white">
<div className="bg-gradient-to-r from-[#4d4d4d] to-[#3e3e3e] h-full max-h-[10rem] w-full justify-between flex rounded-md flex-col gap-4 md:flex-row p-4 text-white">
<div className="flex flex-col">
<p className="text-xs font-[500]">Overview</p>
<p className="text-4xl font-[700]">{data?.event?.name}</p>
</div>
<div className="flex flex-col">
<p className="text-xs font-[500] w-full text-right">Total Amount Raised</p>
<p className="text-xs font-[500] w-full text-right">
Total Amount Raised
</p>
<p className="text-4xl font-bold md:text-right">
&#8377;{data?.event?.money_raised}
</p>
</div>
</div>
<div className="bg-white relative h-full min-h-fit p-4 rounded-md">
<h1 className="font-bold mb-8">Companies & Sponsors</h1>
<Table.ScrollContainer type="native" mah={"80%"} minWidth={500} maw={"100%"}>
<Table.ScrollContainer
type="native"
mah={"80%"}
minWidth={500}
maw={"100%"}
>
<ScrollArea>
<Table
horizontalSpacing="md"
Expand Down
Loading

0 comments on commit 35fd0a4

Please sign in to comment.