Skip to content

Commit

Permalink
changed to arrow fxns
Browse files Browse the repository at this point in the history
  • Loading branch information
manish-singh-bisht committed Apr 21, 2024
1 parent b4f49a3 commit f9cf954
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions app/(dashboard)/repo-settings/[repositoryId]/levels/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { createLevel, deleteLevel, updateLevel } from "@/lib/levels/service";
import { getCurrentUser } from "@/lib/session";
import { TLevel } from "@/types/level";

export async function createLevelAction(levelData: TLevel) {
export const createLevelAction = async (levelData: TLevel) => {
try {
const user = await getCurrentUser();
if (!user || !user.id) {
throw new Error("User must be authenticated to perform this action.");
}
return await createLevel(levelData);
} catch (error) {
throw new Error(`Failed to create level: ${error.message}`);
throw new Error(`Failed to create level.`);
}
}
};

export async function updateLevelAction(updateData: TLevel) {
export const updateLevelAction = async (updateData: TLevel) => {
try {
const user = await getCurrentUser();
if (!user || !user.id) {
Expand All @@ -25,18 +25,18 @@ export async function updateLevelAction(updateData: TLevel) {

return await updateLevel(updateData);
} catch (error) {
throw new Error(`Failed to update level: ${error.message}`);
throw new Error(`Failed to update level.`);
}
}
};

export async function deleteLevelAction(repositoryId: string, levelId: string) {
export const deleteLevelAction = async (repositoryId: string, levelId: string) => {
try {
const user = await getCurrentUser();
if (!user || !user.id) {
throw new Error("User must be authenticated to perform this action.");
}
return await deleteLevel(repositoryId, levelId);
} catch (error) {
throw new Error(`Failed to delete level: ${error.message}`);
throw new Error(`Failed to delete level.`);
}
}
};
26 changes: 13 additions & 13 deletions components/forms/levels-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function LevelsForm({
const isFieldDisabled = (defaultValue: any) => {
return !isEditMode && defaultValue !== undefined && defaultValue !== "";
};
async function handleCreateUpdateLevel(values: TFormSchema, isCreate: boolean) {
const handleCreateUpdateLevel = async (values: TFormSchema, isCreate: boolean) => {
setIsLoading(true);
try {
const isValid = await form.trigger();
Expand All @@ -82,14 +82,14 @@ export function LevelsForm({
}

const icon = values.iconUrl;
const { url, error } = await handleFileUpload(icon, repositoryId);
if (error) {
toast({
title: "Error",
description: error,
});
return;
}
// const { url, error } = await handleFileUpload(icon, repositoryId);
// if (error) {
// toast({
// title: "Error",
// description: error,
// });
// return;
// }

const permissions = {
limitIssues: values.limitIssues,
Expand All @@ -104,7 +104,7 @@ export function LevelsForm({
name: values.name,
description: values.description,
pointThreshold: parseInt(values.pointThreshold, 10),
iconUrl: url,
iconUrl: "https://github.com/shadcn.png",
repositoryId: repositoryId,
permissions: permissions,
});
Expand All @@ -114,7 +114,7 @@ export function LevelsForm({
name: values.name,
description: values.description,
pointThreshold: parseInt(values.pointThreshold, 10),
iconUrl: url,
iconUrl: "https://github.com/shadcn.png",
repositoryId: repositoryId,
permissions: permissions,
});
Expand All @@ -125,12 +125,12 @@ export function LevelsForm({
} catch (err) {
toast({
title: "Error",
description: `Failed to ${isCreate ? "create" : "update"} level.${err.message}`,
description: `Failed to ${isCreate ? "create" : "update"} level.`,
});
} finally {
setIsLoading(false);
}
}
};

async function handleFileChange(event: React.ChangeEvent<HTMLInputElement>) {
const file = event.target.files?.[0];
Expand Down

0 comments on commit f9cf954

Please sign in to comment.