mirror of
https://github.com/ahmadk953/tasko.git
synced 2025-02-12 05:42:07 +00:00
## AI Generated code and Descriptions Improve website performance and efficiency by reducing bundle sizes and implementing caching strategies. * **next.config.ts**: Add `compression` middleware to enable gzip compression for responses. * **Lazy Loading**: Implement lazy loading for images in `app/(platform)/(dashboard)/board/[boardId]/_components/board-update-image.tsx` using the `loading="lazy"` attribute. Add `react-lazyload` library for lazy loading components in `app/(platform)/(dashboard)/board/[boardId]/_components/list-item.tsx` and wrap list items with `LazyLoad` component. * **Database Query Optimization**: Optimize database queries in `actions/copy-card/index.ts`, `actions/copy-list/index.ts`, `actions/create-board/index.ts`, `actions/create-card/index.ts`, `actions/create-list/index.ts`, `actions/delete-board/index.ts`, `actions/delete-card/index.ts`, `actions/delete-list/index.ts`, `actions/stripe-redirect/index.ts`, `actions/update-board/index.ts`, `actions/update-card-order/index.ts`, `actions/update-card/index.ts`, and `actions/update-list/index.ts` by adding appropriate indexes and using `select` to fetch only required fields. * **Dependencies**: Update `package.json` to include `compression` and `react-lazyload` dependencies. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/ahmadk953/tasko?shareId=XXXX-XXXX-XXXX-XXXX).
92 lines
2.2 KiB
TypeScript
92 lines
2.2 KiB
TypeScript
'use server';
|
|
|
|
import { auth } from '@clerk/nextjs/server';
|
|
import { revalidatePath } from 'next/cache';
|
|
import { ACTION, ENTITY_TYPE } from '@prisma/client';
|
|
|
|
import { db } from '@/lib/db';
|
|
import { createAuditLog } from '@/lib/create-audit-log';
|
|
import { createSafeAction } from '@/lib/create-safe-action';
|
|
|
|
import { InputType, ReturnType } from './types';
|
|
import { UpdateBoard } from './schema';
|
|
|
|
const handler = async (data: InputType): Promise<ReturnType> => {
|
|
const { userId, orgId } = await auth();
|
|
|
|
if (!userId || !orgId) return { error: 'Unauthorized' };
|
|
|
|
const { title, id, image } = data;
|
|
let board;
|
|
|
|
try {
|
|
const currentBoard = await db.board.findUnique({
|
|
where: {
|
|
id,
|
|
orgId,
|
|
},
|
|
select: {
|
|
imageId: true,
|
|
imageThumbUrl: true,
|
|
imageFullUrl: true,
|
|
imageUserName: true,
|
|
imageLinkHTML: true,
|
|
imageDownloadUrl: true,
|
|
},
|
|
});
|
|
|
|
const currentImageString = `${currentBoard?.imageId}|${currentBoard?.imageThumbUrl}|${currentBoard?.imageFullUrl}|${currentBoard?.imageUserName}|${currentBoard?.imageLinkHTML}|${currentBoard?.imageDownloadUrl}`;
|
|
|
|
const [
|
|
imageId,
|
|
imageThumbUrl,
|
|
imageFullUrl,
|
|
imageLinkHTML,
|
|
imageUserName,
|
|
imageDownloadUrl,
|
|
] = image?.split('|') || currentImageString.split('|');
|
|
|
|
board = await db.board.update({
|
|
where: {
|
|
id,
|
|
orgId,
|
|
},
|
|
data: {
|
|
title,
|
|
imageId,
|
|
imageThumbUrl,
|
|
imageFullUrl,
|
|
imageLinkHTML,
|
|
imageUserName,
|
|
imageDownloadUrl,
|
|
},
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
orgId: true,
|
|
imageId: true,
|
|
imageThumbUrl: true,
|
|
imageFullUrl: true,
|
|
imageUserName: true,
|
|
imageLinkHTML: true,
|
|
imageDownloadUrl: true,
|
|
},
|
|
});
|
|
|
|
await createAuditLog({
|
|
entityTitle: board.title,
|
|
entityType: ENTITY_TYPE.BOARD,
|
|
entityId: board.id,
|
|
action: ACTION.UPDATE,
|
|
});
|
|
} catch (error) {
|
|
return {
|
|
error: 'Failed to update board',
|
|
};
|
|
}
|
|
|
|
revalidatePath(`/board/${id}`);
|
|
return { data: board };
|
|
};
|
|
|
|
export const updateBoard = createSafeAction(UpdateBoard, handler);
|