Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checklist #2168

Merged
merged 9 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Required type fix
  • Loading branch information
timmo001 committed May 27, 2023
commit 204c737bd8089a2f71fa1292451bb0fb962eb2c1
4 changes: 2 additions & 2 deletions src/app/dashboards/[dashboardId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async function Page({
* The dashboard object retrieved from the database.
* Contains all the sections and widgets associated with the dashboard.
*/
let dashboard: DashboardModel | null = await prisma.dashboard.findUnique({
let dashboard: DashboardModel | null = (await prisma.dashboard.findUnique({
where: {
id: params.dashboardId,
},
Expand All @@ -43,7 +43,7 @@ export default async function Page({
orderBy: { position: "asc" },
},
},
});
})) as DashboardModel | null;

if (!dashboard) return notFound();

Expand Down
93 changes: 46 additions & 47 deletions src/components/dashboard/views/widgets/Checklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,52 @@ import { useState } from "react";
import type { WidgetChecklistModel, WidgetModel } from "@/types/widget.type";
import { widgetChecklistUpdate } from "@/utils/serverActions/widget";

export function WidgetChecklist({
dashboardId,
sectionId,
widget,
}: {
dashboardId: string;
sectionId: string;
widget: WidgetModel<WidgetChecklistModel>;
}): JSX.Element {
const { id } = widget;
const { items } = widget.data;

return (
<Grid2 container direction="column">
{items.map((item: WidgetChecklistItemModel) => (
<WidgetChecklistItem
key={item.id}
dashboardId={dashboardId}
item={item}
sectionId={sectionId}
/>
))}
<Grid2>
<Button
fullWidth
variant="outlined"
sx={{ mt: 1 }}
onClick={async () => {
await widgetChecklistUpdate(
dashboardId,
sectionId,
id,
"",
"content",
""
);
}}
>
<AddRounded />
Add item
</Button>
</Grid2>
</Grid2>
);
}

function WidgetChecklistItem({
dashboardId,
item,
Expand Down Expand Up @@ -97,50 +143,3 @@ function WidgetChecklistItem({
</Grid2>
);
}

export function WidgetChecklist({
dashboardId,
sectionId,
widget,
}: {
dashboardId: string;
sectionId: string;
widget: WidgetModel<WidgetChecklistModel>;
}): JSX.Element {
const { id } = widget;
if (!widget.data) return <div>Widget data not found</div>;
const { items } = widget.data;

return (
<Grid2 container direction="column">
{items.map((item: WidgetChecklistItemModel) => (
<WidgetChecklistItem
key={item.id}
dashboardId={dashboardId}
item={item}
sectionId={sectionId}
/>
))}
<Grid2>
<Button
fullWidth
variant="outlined"
sx={{ mt: 1 }}
onClick={async () => {
await widgetChecklistUpdate(
dashboardId,
sectionId,
id,
"",
"content",
""
);
}}
>
<AddRounded />
Add item
</Button>
</Grid2>
</Grid2>
);
}
2 changes: 1 addition & 1 deletion src/types/widget.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type WidgetWithSectionModel = Widget & {

// Combined types for widget and generic widget data
export type WidgetModel<T = any> = Widget & {
data?: T;
data: T;
};

export enum WidgetAction {
Expand Down