Skip to content

Commit

Permalink
feat: minor adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
Paribesh01 committed Oct 11, 2024
1 parent 949f850 commit b98bd7c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/components/CompanyTabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ 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 @@ -39,7 +42,7 @@ export default function CompanyTable({
variant: 'destructive',
});
}

router.push(pathName);
toast({
title: response.msg || 'Company deleted successfully',
variant: 'success',
Expand Down
5 changes: 3 additions & 2 deletions src/components/UpdateCompanyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import { toast } from './ui/use-toast';
import { updateCompany } from '@/actions/company.actions'; // Assuming you have an update action
import { CompanyType } from '@/types/company.types';
import { Button } from './ui/button';
import { useRouter } from 'next/navigation';

type Props = {
companyData: CompanyType;
setIsDialogOpen: (open: boolean) => void;
};

export const UpdateCompanyForm = ({ companyData, setIsDialogOpen }: Props) => {
const router = useRouter();
const [file, setFile] = useState<File | null>(null);
const [previewImg, setPreviewImg] = useState<string | null>(null);
const companyLogoImg = useRef<HTMLImageElement>(null);
Expand Down Expand Up @@ -86,7 +88,6 @@ export const UpdateCompanyForm = ({ companyData, setIsDialogOpen }: Props) => {
const selectedFile = e.target.files[0];
if (!selectedFile) return;

// Basic file validation
if (!selectedFile.type.startsWith('image/')) {
return toast({
title: 'Invalid file type',
Expand Down Expand Up @@ -121,7 +122,7 @@ export const UpdateCompanyForm = ({ companyData, setIsDialogOpen }: Props) => {
variant: 'destructive',
});
}

router.push('/manage/company');
toast({
title: response.msg || 'Company updated successfully',
variant: 'success',
Expand Down
5 changes: 4 additions & 1 deletion src/components/company-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { uploadFileAction } from '@/actions/upload-to-cdn';
import { toast } from './ui/use-toast';
import { createCompany } from '@/actions/company.actions';
import { usePathname, useRouter } from 'next/navigation';

export const CompanyForm = ({ setIsDialogOpen }: any) => {
const router = useRouter();
const pathname = usePathname();
const [file, setFile] = useState<File | null>(null);
const [previewImg, setPreviewImg] = useState<string | null>(null);
const [isUploading, setIsUploading] = useState(false);
Expand Down Expand Up @@ -111,7 +114,7 @@ export const CompanyForm = ({ setIsDialogOpen }: any) => {
variant: 'destructive',
});
}

router.push(pathname);
toast({
title: response.msg || 'Company created successfully',
variant: 'success',
Expand Down

0 comments on commit b98bd7c

Please sign in to comment.