Skip to content

Commit

Permalink
Update - CRM - Kanban
Browse files Browse the repository at this point in the history
- finished

Update - Project - Kanban
- add ... menu
  • Loading branch information
pdovhomilja committed Sep 18, 2023
1 parent 88c1487 commit 8737113
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 47 deletions.
4 changes: 2 additions & 2 deletions app/[locale]/(routes)/crm/dashboard/_components/CRMKanban.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import axios from "axios";
import { useRouter } from "next/navigation";
import { useToast } from "@/components/ui/use-toast";
import LoadingComponent from "@/components/LoadingComponent";

import { format } from "date-fns";
import LoadingModal from "@/components/modals/loading-modal";
import {
Expand Down Expand Up @@ -164,7 +164,7 @@ const CRMKanban = ({ salesStages, opportunities: data }: CRMKanbanProps) => {
<div>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<DotsHorizontalIcon className="w-4 h-4" />
<DotsHorizontalIcon className="w-4 h-4 text-slate-600" />
</DropdownMenuTrigger>
<DropdownMenuContent
align="end"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import RightViewModalNoTrigger from "@/components/modals/right-view-notrigger";
import RossumCockpit from "../components/RossumCockpit";
import Link from "next/link";
import LoadingModal from "@/components/modals/loading-modal";
import { useAppStore } from "@/store/store";
import { Edit } from "lucide-react";

interface DataTableRowActionsProps<TData> {
row: Row<TData>;
Expand All @@ -43,6 +45,9 @@ export function DataTableRowActions<TData>({
const [openView, setOpenView] = useState(false);
const [openRossumView, setOpenRossumView] = useState(false);

//zustand
const { setIsOpen } = useAppStore();

const router = useRouter();
const { toast } = useToast();

Expand Down Expand Up @@ -206,6 +211,14 @@ export function DataTableRowActions<TData>({
<Link href={invoice.invoice_file_url} target={"_blank"}>
<DropdownMenuItem>Preview invoice in new window</DropdownMenuItem>
</Link>
<DropdownMenuItem
onClick={() => {
setIsOpen(true);
}}
>
<Edit className="mr-2 w-4 h-4" />
Create task from Notion
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuLabel>Rossum</DropdownMenuLabel>
<DropdownMenuItem onClick={() => setOpenRossumView(true)}>
Expand Down
258 changes: 258 additions & 0 deletions app/[locale]/(routes)/invoice/dialogs/NewTask.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
"use client";

import LoadingComponent from "@/components/LoadingComponent";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTrigger,
DialogTitle,
DialogDescription,
DialogFooter,
} from "@/components/ui/dialog";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Textarea } from "@/components/ui/textarea";
import { useToast } from "@/components/ui/use-toast";
import { useAppStore } from "@/store/store";
import { zodResolver } from "@hookform/resolvers/zod";
import axios from "axios";
import { useRouter } from "next/navigation";

import React, { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";

type Props = {
users: any;
boards: any;
};

const NewTaskDialog = ({ users, boards }: Props) => {
//const [open, setOpen] = useState(false);
const [isLoading, setIsLoading] = useState(false);

const { isOpen, setIsOpen } = useAppStore();

const [isMounted, setIsMounted] = useState(false);

const router = useRouter();
const { toast } = useToast();

const formSchema = z.object({
title: z.string().min(3).max(255),
user: z.string().min(3).max(255),
board: z.string().min(3).max(255),
priority: z.string().min(3).max(10),
content: z.string().min(3).max(500),
});

type NewAccountFormValues = z.infer<typeof formSchema>;

const form = useForm<NewAccountFormValues>({
resolver: zodResolver(formSchema),
});

useEffect(() => {
setIsMounted(true);
}, [form]);

if (!isMounted) {
return null;
}

//Actions

const onSubmit = async (data: NewAccountFormValues) => {
setIsLoading(true);

try {
await axios.post(`/api/projects/tasks/create-task`, data);
toast({
title: "Success",
description: `New task: ${data.title}, created successfully`,
});
} catch (error: any) {
toast({
variant: "destructive",
title: "Error",
description: error?.response?.data,
});
} finally {
setIsLoading(false);
setIsOpen(false);
}
setIsLoading(false);
setIsOpen(false);
};

return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
{/* <DialogTrigger>
<Button className="px-2">Create task</Button>
</DialogTrigger> */}
<DialogContent className="">
<DialogHeader>
<DialogTitle className="p-2">Create New Tas from Invoice</DialogTitle>
<DialogDescription className="p-2"></DialogDescription>
</DialogHeader>
{isLoading ? (
<LoadingComponent />
) : (
<div className="flex flex-col w-full ">
{/* <pre>
<code>{JSON.stringify(form.getValues(), null, 2)}</code>
</pre> */}
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className="h-full w-full space-y-3"
>
<div className="flex flex-col space-y-3">
<FormField
control={form.control}
name="title"
render={({ field }) => (
<FormItem>
<FormLabel>New task name</FormLabel>
<FormControl>
<Input
disabled={isLoading}
placeholder="Enter task name"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="content"
render={({ field }) => (
<FormItem>
<FormLabel>Task description</FormLabel>
<FormControl>
<Textarea
disabled={isLoading}
placeholder="Enter task description"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>

<FormField
control={form.control}
name="user"
render={({ field }) => (
<FormItem>
<FormLabel>Assigned to</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select assigned user" />
</SelectTrigger>
</FormControl>
<SelectContent>
{users.map((user: any) => (
<SelectItem key={user.id} value={user.id}>
{user.name}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="board"
render={({ field }) => (
<FormItem>
<FormLabel>Choose project</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select tasks board" />
</SelectTrigger>
</FormControl>
<SelectContent>
{boards.map((board: any) => (
<SelectItem key={board.id} value={board.id}>
{board.title}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="priority"
render={({ field }) => (
<FormItem>
<FormLabel>Choose task priority</FormLabel>
<Select
onValueChange={field.onChange}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select tasks priority" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="low">Low</SelectItem>
<SelectItem value="medium">Medium</SelectItem>
<SelectItem value="high">High</SelectItem>
<SelectItem value="critical">Critical</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="flex w-full justify-end space-x-2 pt-2">
<DialogTrigger asChild>
<Button variant={"destructive"}>Cancel</Button>
</DialogTrigger>
<Button type="submit">Create</Button>
</div>
</form>
</Form>
</div>
)}
</DialogContent>
</Dialog>
);
};

export default NewTaskDialog;
6 changes: 6 additions & 0 deletions app/[locale]/(routes)/invoice/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ import { MyAccountSettingsForm } from "./components/MyAccountSettingsForm";
import { Button } from "@/components/ui/button";
import RightViewModal from "@/components/modals/right-view-modal";
import { MyAccount } from "@prisma/client";
import { getActiveUsers } from "@/actions/get-users";
import { getBoards } from "@/actions/projects/get-boards";
import NewTaskDialog from "./dialogs/NewTask";

const InvoicePage = async () => {
const session = await getServerSession(authOptions);
const invoices: any = await getInvoices();
const myAccountSettings: MyAccount | null = await getAccountSettings();
const users = await getActiveUsers();
const boards = await getBoards(session?.user.id!);

return (
<Container
title="Invoices"
description={"Everything you need to know about invoices and TAX"}
>
<NewTaskDialog users={users} boards={boards} />
<div className="flex justify-between py-5 w-full">
<div className="flex space-x-2">
<ModalDropzone buttonLabel="Upload pdf" />
Expand Down
Loading

0 comments on commit 8737113

Please sign in to comment.