Skip to content

Commit

Permalink
fix the details issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Megha-Dev-19 committed Aug 25, 2024
1 parent bf1f106 commit 254d485
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 81 deletions.
43 changes: 43 additions & 0 deletions src/app/(authenticated)/project-details/details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";

import dayjs from "dayjs";
import { Api } from "@/core/trpc";
import { PageLayout } from "@/designSystem/layouts/Page.layout";
import { Typography, Card } from "antd";
const { Title, Paragraph, Text } = Typography;

export default function ProjectDetailsComponent({ projectId }) {
console.log("calleeedd", projectId);
const { data: project } = Api.project.findUnique.useQuery({
where: { id: projectId },
include: { user: true },
});

return (
<PageLayout layout="narrow">
{project && (
<Card title="Project Overview">
<Title level={4}>{project.name}</Title>
<Text>Description: {project.description}</Text>
<br />
<Text>Overview: {project.overview}</Text>
<br />
<Text>Time Estimate: {project.timeEstimate?.toString()} hours</Text>
<br />
<Text>Budget Buffer: ${project.budgetBuffer?.toString()}</Text>
<br />
<Text>Profit Margin: {project.profitMargin?.toString()}%</Text>
<br />
<Text>
Date Created: {dayjs(project.dateCreated).format("MMMM D, YYYY")}
</Text>
<br />
<Text>
Date Updated: {dayjs(project.dateUpdated).format("MMMM D, YYYY")}
</Text>
<br />
</Card>
)}
</PageLayout>
);
}
125 changes: 44 additions & 81 deletions src/app/(authenticated)/project-details/page.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
'use client'
"use client";

import dayjs from 'dayjs'
import { useUserContext } from '@/core/context'
import { Api } from '@/core/trpc'
import { PageLayout } from '@/designSystem/layouts/Page.layout'
import { Button, Form, Input, Typography, Card, Spin } from 'antd'
import { useParams, useRouter } from 'next/navigation'
import { useSnackbar } from 'notistack'
import { useEffect } from 'react'
const { Title, Paragraph, Text } = Typography
import dayjs from "dayjs";
import { useUserContext } from "@/core/context";
import { Api } from "@/core/trpc";
import { PageLayout } from "@/designSystem/layouts/Page.layout";
import { Button, Form, Input, Typography, Card, Spin } from "antd";
import { useParams, useRouter } from "next/navigation";
import { useSnackbar } from "notistack";
import ProjectDetailsComponent from "./details";
import { useState } from "react";
const { Title, Paragraph, Text } = Typography;

export default function ProjectDetailsPage() {
const router = useRouter()
const params = useParams<any>()
const { user } = useUserContext()
const { enqueueSnackbar } = useSnackbar()
const router = useRouter();
const params = useParams<any>();
const { user } = useUserContext();
const { enqueueSnackbar } = useSnackbar();

const [form] = Form.useForm()
const [form] = Form.useForm();

const { mutateAsync: createProject } = Api.project.create.useMutation()
const { mutateAsync: updateProject } = Api.project.update.useMutation()
const { mutateAsync: createProject } = Api.project.create.useMutation();
const { mutateAsync: updateProject } = Api.project.update.useMutation();
const { mutateAsync: handleCurlRequest, isLoading: isLoadingWordWare } =
Api.wordware.handleCurlRequest.useMutation()

const { data: project, isLoading: projectLoading } = Api.project.findUnique.useQuery({
where: { id: params.id },
include: { user: true },
})
Api.wordware.handleCurlRequest.useMutation();
const [projectId, setProjectId] = useState(null);
const [loading, setLoading] = useState(false);

const handleFormSubmit = async (values: any) => {
try {
setLoading(true);
const projectCreated = await createProject({
data: {
name: values.name,
Expand All @@ -38,26 +37,27 @@ export default function ProjectDetailsPage() {
budgetBuffer: values.budgetBuffer,
location: values.location,
profitMargin: values.profitMargin,
userId: user.id,
userId: "20eebdd2-d798-47ca-a1e1-9dc593df7037",
},
})
enqueueSnackbar('Project created successfully', { variant: 'success' })
});
enqueueSnackbar("Project created successfully", { variant: "success" });

// Call the wordware router to handle the cURL request
const response = await handleCurlRequest({
body: values,
})
});

await updateProject({
where: { id: projectCreated.id },
data: { overview: response?.overview },
})

router.push('/home')
});
setProjectId(projectCreated.id);
setLoading(false);
} catch (error) {
enqueueSnackbar('Failed to create project', { variant: 'error' })
setLoading(false);
enqueueSnackbar("Failed to create project", { variant: "error" });
}
}
};

return (
<PageLayout layout="narrow">
Expand All @@ -70,15 +70,15 @@ export default function ProjectDetailsPage() {
<Form.Item
name="name"
label="Project Name"
rules={[{ required: true, message: 'Please enter the project name' }]}
rules={[{ required: true, message: "Please enter the project name" }]}
>
<Input.TextArea placeholder="Enter project name" />
</Form.Item>
<Form.Item
name="description"
label="Project Details"
rules={[
{ required: true, message: 'Please enter the project details' },
{ required: true, message: "Please enter the project details" },
]}
>
<Input.TextArea placeholder="Enter project details" />
Expand All @@ -87,7 +87,7 @@ export default function ProjectDetailsPage() {
name="timeEstimate"
label="Time Estimates"
rules={[
{ required: true, message: 'Please enter the time estimates' },
{ required: true, message: "Please enter the time estimates" },
]}
>
<Input.TextArea placeholder="Enter time estimates" />
Expand All @@ -96,7 +96,7 @@ export default function ProjectDetailsPage() {
name="budgetBuffer"
label="Budget Buffers"
rules={[
{ required: true, message: 'Please enter the budget buffers' },
{ required: true, message: "Please enter the budget buffers" },
]}
>
<Input.TextArea placeholder="Enter budget buffers" />
Expand All @@ -105,7 +105,7 @@ export default function ProjectDetailsPage() {
name="task_breakdown"
label="Task Breakdown"
rules={[
{ required: true, message: 'Please enter the task breakdown' },
{ required: true, message: "Please enter the task breakdown" },
]}
>
<Input.TextArea placeholder="Enter task breakdown" />
Expand All @@ -114,78 +114,41 @@ export default function ProjectDetailsPage() {
name="roles_seniority"
label="Roles Seniority"
rules={[
{ required: true, message: 'Please enter the roles seniority' },
{ required: true, message: "Please enter the roles seniority" },
]}
>
<Input.TextArea placeholder="Enter roles seniority" />
</Form.Item>
<Form.Item
name="location"
label="Location"
rules={[{ required: true, message: 'Please enter the location' }]}
rules={[{ required: true, message: "Please enter the location" }]}
>
<Input placeholder="Enter location" />
</Form.Item>
<Form.Item
name="payroll"
label="Payroll"
rules={[{ required: true, message: 'Please enter the payroll' }]}
rules={[{ required: true, message: "Please enter the payroll" }]}
>
<Input.TextArea placeholder="Enter payroll" />
</Form.Item>
<Form.Item
name="profitMargin"
label="Profit Margins"
rules={[
{ required: true, message: 'Please enter the profit margins' },
{ required: true, message: "Please enter the profit margins" },
]}
>
<Input.TextArea placeholder="Enter profit margins" />
</Form.Item>
<Form.Item>
<Button
loading={isLoadingWordWare}
type="primary"
htmlType="submit"
block
>
<Button loading={loading} type="primary" htmlType="submit" block>
Submit
</Button>
</Form.Item>
</Form>
{projectLoading ? (
<Spin />
) : (
project && (
<Card title="Project Overview">
<Title level={4}>{project.name}</Title>
<Text>Description: {project.description}</Text>
<br />
<Text>Overview: {project.overview}</Text>
<br />
<Text>
Time Estimate: {project.timeEstimate?.toString()} hours
</Text>
<br />
<Text>
Budget Buffer: ${project.budgetBuffer?.toString()}
</Text>
<br />
<Text>
Profit Margin: {project.profitMargin?.toString()}%
</Text>
<br />
<Text>
Date Created: {dayjs(project.dateCreated).format('MMMM D, YYYY')}
</Text>
<br />
<Text>
Date Updated: {dayjs(project.dateUpdated).format('MMMM D, YYYY')}
</Text>
<br />
</Card>
)
)}
{projectId && <ProjectDetailsComponent projectId={projectId} />}
</PageLayout>
)
);
}

0 comments on commit 254d485

Please sign in to comment.