Skip to content

Commit

Permalink
Refactor: Remove unused dependency and simplify company page rendering
Browse files Browse the repository at this point in the history
- Removed the unused dependency "100xdevs-job-board" from package.json
- Simplified the rendering of the company page by removing unnecessary div container and flex styling
- Updated the date format in the CompanyTable component to use toDateString() instead of toLocaleDateString()
- Added a window.location.reload() to refresh the company list after deleting a company
- Removed the unused router and pathName variables in the CompanyTable component
- Removed the unused random input styling in the DeleteAccountDialog component
  • Loading branch information
CuriousCoder00 committed Oct 20, 2024
1 parent a4aff9d commit 7a0c200
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 124 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"seed": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' prisma/seed.ts"
},
"dependencies": {
"100xdevs-job-board": "file:",
"@aws-sdk/client-s3": "^3.645.0",
"@aws-sdk/s3-request-presigner": "^3.645.0",
"@emotion/react": "^11.13.3",
Expand Down
6 changes: 1 addition & 5 deletions src/app/manage/company/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import React from 'react';
const page = async () => {
const companies = await getAllCompanies();

return (
<div className="mt-10 flex flex-col items-center">
<CompanyTable company={companies.data.companies} />
</div>
);
return <CompanyTable company={companies.data.companies} />;
};

export default page;
233 changes: 116 additions & 117 deletions src/components/CompanyTabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from './ui/dialog';
import { UpdateCompanyForm } from './UpdateCompanyForm';
import { toast } from './ui/use-toast';
import { deleteCompany } from '@/actions/company.actions';
import { usePathname, useRouter } from 'next/navigation';

export default function CompanyTable({
company: companies,
}: {
company: CompanyType[];
}) {
const router = useRouter();
const pathName = usePathname();
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const [isUpdateModalOpen, setIsUpdateModalOpen] = useState(false);
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
Expand All @@ -42,12 +39,12 @@ export default function CompanyTable({
variant: 'destructive',
});
}
router.push(pathName);
toast({
title: response.msg || 'Company deleted successfully',
variant: 'success',
});
// Optionally refresh the company list or update state to remove the deleted company
window.location.reload();
} catch (_error) {
toast({
title: 'Something went wrong while deleting the company',
Expand All @@ -58,131 +55,133 @@ export default function CompanyTable({
};

return (
<div className="container mx-auto py-10">
<div className="flex justify-between items-center mb-6">
<h1 className="text-2xl font-bold">Companies</h1>
<Button onClick={() => setIsCreateModalOpen(true)}>
<PlusIcon className="mr-2 h-4 w-4" /> Add Company
</Button>
</div>
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Email</TableHead>
<TableHead>Website</TableHead>
<TableHead>Created At</TableHead>
<TableHead>Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{companies.map((company, index) => (
<TableRow key={index}>
<TableCell>{company.name}</TableCell>
<TableCell>{company.email}</TableCell>
<TableCell>{company.website || 'N/A'}</TableCell>
<TableCell>
{new Date(company.createdAt).toLocaleDateString()}
</TableCell>
<TableCell>
<div className="flex space-x-2">
<Button
variant="outline"
size="sm"
onClick={() => {
setSelectedCompany(company);
setIsUpdateModalOpen(true);
}}
>
<Pencil className="h-4 w-4" />
</Button>
<Button
variant="outline"
size="sm"
onClick={() => {
setSelectedCompany(company);
setIsDeleteModalOpen(true);
}}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</TableCell>
<div className="mt-10 flex flex-col items-center">
<div className="container mx-auto py-10">
<div className="flex justify-between items-center mb-6">
<h1 className="text-2xl font-bold">Companies</h1>
<Button onClick={() => setIsCreateModalOpen(true)}>
<PlusIcon className="mr-2 h-4 w-4" /> Add Company
</Button>
</div>
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Email</TableHead>
<TableHead>Website</TableHead>
<TableHead>Created At</TableHead>
<TableHead>Actions</TableHead>
</TableRow>
))}
</TableBody>
</Table>

{/* Create Company Modal */}
<Dialog open={isCreateModalOpen} onOpenChange={setIsCreateModalOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>
<h2 className="text-lg font-semibold mb-4 text-gray-300">
Company Details
</h2>
</DialogTitle>
</DialogHeader>
<CompanyForm setIsDialogOpen={setIsCreateModalOpen} />
</DialogContent>
</Dialog>
</TableHeader>
<TableBody>
{companies.map((company, index) => (
<TableRow key={index}>
<TableCell>{company.name}</TableCell>
<TableCell>{company.email}</TableCell>
<TableCell>{company.website || 'N/A'}</TableCell>
<TableCell>
{new Date(company.createdAt).toDateString()}
</TableCell>
<TableCell>
<div className="flex space-x-2">
<Button
variant="outline"
size="sm"
onClick={() => {
setSelectedCompany(company);
setIsUpdateModalOpen(true);
}}
>
<Pencil className="h-4 w-4" />
</Button>
<Button
variant="outline"
size="sm"
onClick={() => {
setSelectedCompany(company);
setIsDeleteModalOpen(true);
}}
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>

{/* Update Company Modal */}
{selectedCompany && (
<Dialog open={isUpdateModalOpen} onOpenChange={setIsUpdateModalOpen}>
{/* Create Company Modal */}
<Dialog open={isCreateModalOpen} onOpenChange={setIsCreateModalOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>
<h2 className="text-lg font-semibold mb-4 text-gray-300">
Update Company
Company Details
</h2>
</DialogTitle>
</DialogHeader>
<UpdateCompanyForm
companyData={selectedCompany}
setIsDialogOpen={setIsUpdateModalOpen}
/>
<CompanyForm setIsDialogOpen={setIsCreateModalOpen} />
</DialogContent>
</Dialog>
)}

{/* Delete Company Confirmation Dialog */}
{selectedCompany && (
<Dialog open={isDeleteModalOpen} onOpenChange={setIsDeleteModalOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>
<h2 className="text-lg font-semibold mb-4 text-gray-300">
Delete Company
</h2>
</DialogTitle>
</DialogHeader>
<p className="mb-4">
Are you sure you want to delete the company{' '}
<strong>{selectedCompany.name}</strong>?
</p>
<div className="flex justify-end space-x-2">
<Button
variant="outline"
onClick={() => setIsDeleteModalOpen(false)}
>
Cancel
</Button>
<Button
variant="destructive"
onClick={() => {
if (selectedCompany) {
handleDeleteCompany(selectedCompany.id);
}
setIsDeleteModalOpen(false);
}}
>
Delete
</Button>
</div>
</DialogContent>
</Dialog>
)}
{/* Update Company Modal */}
{selectedCompany && (
<Dialog open={isUpdateModalOpen} onOpenChange={setIsUpdateModalOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>
<h2 className="text-lg font-semibold mb-4 text-gray-300">
Update Company
</h2>
</DialogTitle>
</DialogHeader>
<UpdateCompanyForm
companyData={selectedCompany}
setIsDialogOpen={setIsUpdateModalOpen}
/>
</DialogContent>
</Dialog>
)}

{/* Delete Company Confirmation Dialog */}
{selectedCompany && (
<Dialog open={isDeleteModalOpen} onOpenChange={setIsDeleteModalOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>
<h2 className="text-lg font-semibold mb-4 text-gray-300">
Delete Company
</h2>
</DialogTitle>
</DialogHeader>
<p className="mb-4">
Are you sure you want to delete the company{' '}
<strong>{selectedCompany.name}</strong>?
</p>
<div className="flex justify-end space-x-2">
<Button
variant="outline"
onClick={() => setIsDeleteModalOpen(false)}
>
Cancel
</Button>
<Button
variant="destructive"
onClick={() => {
if (selectedCompany) {
handleDeleteCompany(selectedCompany.id);
}
setIsDeleteModalOpen(false);
}}
>
Delete
</Button>
</div>
</DialogContent>
</Dialog>
)}
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion src/components/profile/DeleteAccountDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const DeleteAccountDialog = () => {
<input
{...register('random')}
id="random"
className=" mt-2 p-2 rounded-md font-bold p-4 rounded-md w-full bg-gray-200 dark:bg-black outline-none text-black dark:text-white"
className=" mt-2 p-2 rounded-md font-bold w-full bg-gray-200 dark:bg-black outline-none text-black dark:text-white"
onPaste={(e: ClipboardEvent<HTMLInputElement>) =>
e.preventDefault()
}
Expand Down

0 comments on commit 7a0c200

Please sign in to comment.