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

refactor: ♻️ improve file, folder structure #264

Merged
merged 2 commits into from
Nov 23, 2024
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
chore: 🔨 replace .error with .log
  • Loading branch information
moinulmoin committed Nov 23, 2024
commit dd8b62c123997e186a6c887b70533795f62e52af
4 changes: 2 additions & 2 deletions src/app/[locale]/dashboard/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function Error({
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
console.log(error);
}, [error]);

return (
<div className="flex h-[calc(100vh-160px)] w-full flex-col items-center justify-center gap-y-4">
<h2 className=" text-5xl font-bold text-destructive">
<h2 className="text-5xl font-bold text-destructive">
Oops, Something Went Wrong!
</h2>
<Button onClick={() => reset()}>Try Again</Button>
Expand Down
15 changes: 9 additions & 6 deletions src/app/[locale]/dashboard/projects/[projectId]/delete-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { Button } from "~/components/ui/button";
import { Card, CardDescription, CardTitle } from "~/components/ui/card";
import { toast } from "~/hooks/use-toast";
import { isRedirectError } from "~/lib/utils";
import { deleteProjectById } from "../action";

export default function DeleteCard({ id }: { id: string }) {
Expand All @@ -27,12 +28,14 @@ export default function DeleteCard({ id }: { id: string }) {
});
})
.catch((error) => {
console.error(error);
toast({
title: "Error deleting project.",
description: "Please try again.",
variant: "destructive",
});
console.log(error);
if (!isRedirectError(error)) {
toast({
title: "Error deleting project.",
description: "Please try again.",
variant: "destructive",
});
}
})
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ import { toast } from "~/hooks/use-toast";
import { updateProjectById } from "../action";
import { projectSchema, type ProjectFormValues } from "../create-project-modal";

// const projectEditSchema = projectSchema.extend({
// id: z.string().readonly(),
// });

// type ProjectEditValues = z.infer<typeof projectEditSchema>;

export default function EditableDetails({
initialValues,
}: {
Expand All @@ -42,7 +36,7 @@ export default function EditableDetails({
});
form.reset();
} catch (error) {
console.error(error);
console.log(error);
toast({
title: "Error creating project.",
description: "Please try again.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function CreateProjectModal() {
form.reset();
setIsOpen(false);
} catch (error) {
console.error({ error });
console.log(error);
if (error instanceof FreePlanLimitError) {
return toast({
title: "Free plan limit reached. Please upgrade your plan.",
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/dashboard/settings/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function removeUserOldImageFromCDN(
await utapi.deleteFiles(currentImageFileKey as string);
}
} catch (e) {
console.error(e);
console.log(e);
const newImageFileKey = getImageKeyFromUrl(newImageUrl);
await utapi.deleteFiles(newImageFileKey as string);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/dashboard/settings/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function Error({
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
console.log(error);
}, [error]);

return (
<div className="flex h-full w-full flex-col items-center justify-center gap-y-4">
<h2 className=" text-4xl font-bold text-destructive">
<h2 className="text-4xl font-bold text-destructive">
Something Went Wrong!
</h2>
<Button onClick={() => reset()}>Try Again</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/dashboard/settings/settings-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function SettingsForm({ currentUser }: { currentUser: User }) {
try {
await removeNewImageFromCDN(getValues().picture);
} catch (error) {
console.error(error);
console.log(error);
}
}
reset();
Expand Down
4 changes: 2 additions & 2 deletions src/app/global-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function GlobalError({
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
console.log(error);
}, [error]);

return (
<div className="flex h-[calc(100vh-160px)] w-full flex-col items-center justify-center gap-y-4">
<h2 className=" text-5xl font-bold text-destructive">
<h2 className="text-5xl font-bold text-destructive">
Oops, Something Went Wrong!
</h2>
<Button onClick={() => reset()}>Try Again</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/image-upload-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function ImageUploadModal({
}
},
onUploadError: (e) => {
console.error(e);
console.log(e);
toast({
title: "Error occurred while uploading!",
variant: "destructive",
Expand Down
10 changes: 10 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ export class FreePlanLimitError extends Error {
super(message);
}
}

export function isRedirectError(error: unknown): boolean {
return (
error !== null &&
typeof error === "object" &&
"digest" in error &&
typeof error.digest === "string" &&
error.digest.includes("NEXT_REDIRECT")
);
}