Skip to content

Commit

Permalink
refactor: rename "errors" module to "error"
Browse files Browse the repository at this point in the history
  • Loading branch information
flsilva committed Nov 26, 2023
1 parent 3f2444e commit df3010b
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app/app/onboarding/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Link from 'next/link';
import { redirect } from 'next/navigation';
import { twMerge } from 'tailwind-merge';
import { buttonGreenClassName } from '@/modules/shared/control/button/buttonClassName';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';
import { getProjects } from '@/modules/app/projects/ProjectsRepository';

export default async function OnboardingPage() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/auth/error.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { DefaultError } from '@/modules/shared/errors/DefaultError';
import { DefaultError } from '@/modules/shared/error/DefaultError';

export default function AuthError({ error, reset }: { error: Error; reset: () => void }) {
return <DefaultError error={error} reset={reset} />;
Expand Down
2 changes: 1 addition & 1 deletion src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { DefaultError } from '@/modules/shared/errors/DefaultError';
import { DefaultError } from '@/modules/shared/error/DefaultError';

export default function RootError({ error, reset }: { error: Error; reset: () => void }) {
return <DefaultError error={error} reset={reset} />;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/projects/NoTasksInProject.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';
import { getTasks } from '@/modules/app/tasks/TasksRepository';

interface NoTasksInProjectProps {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/projects/ProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { buttonGreenClassName } from '@/modules/shared/control/button/buttonClas
import { SubmitButton } from '@/modules/shared/control/button/SubmitButton';
import { inputTextClassName } from '@/modules/shared/control/input/inputTextClassName';
import { ServerError } from '@/modules/shared/data-access/ServerResponse';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';
import { Form } from '@/modules/shared/form/Form';
import { FormErrorList } from '@/modules/shared/form/FormErrorList';
import { ProjectDto, createProject, getProjectById, updateProject } from './ProjectsRepository';
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/projects/ProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import 'server-only';
import { twMerge } from 'tailwind-merge';
import { ClassNamePropsOptional } from '@/modules/shared/ClassNameProps';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';
import { ProjectListItem } from './ProjectListItem';
import { ProjectStatus } from './ProjectStatus';
import { getProjects } from './ProjectsRepository';
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/projects/ProjectPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { notFound } from 'next/navigation';
import { getProjectById } from './ProjectsRepository';
import { ProjectMutationDropdown } from './ProjectMutationDropdown';
import { WarningFeedback } from '@/modules/shared/feedback/WarningFeedback';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';

export interface ProjectPageHeaderProps {
readonly id: string;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/projects/ProjectsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
createServerErrorResponse,
createServerSuccessResponse,
} from '@/modules//shared/data-access/ServerResponse';
import { genericAwareOfInternalErrorMessage } from '@/modules/app//shared/errors/errorMessages';
import { genericAwareOfInternalErrorMessage } from '@/modules/app//shared/error/errorMessages';
import { getServerSideUser } from '@/modules/app/users/UsersRepository';
import { createProjectSchema, deleteProjectSchema, updateProjectSchema } from './ProjectsDomain';

Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/projects/ProjectsSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'server-only';
import { ProjectDto, getProjects } from '@/modules/app/projects/ProjectsRepository';
import { Select, SelectItemProps, SelectProps } from '@/modules/shared/control/select/Select';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';

export type ProjectsSelectProps = Omit<SelectProps, 'items'>;

Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/tasks/DeleteTaskAlertDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'server-only';
import { notFound } from 'next/navigation';
import { AlertDialog, AlertDialogBody } from '@/modules/shared/dialog/AlertDialog';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';
import { Form } from '@/modules/shared/form/Form';
import { FormErrorList } from '@/modules/shared/form/FormErrorList';
import { RouterAction } from '@/modules/shared/router/RouterActions';
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/tasks/TaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { notFound } from 'next/navigation';
import { twMerge } from 'tailwind-merge';
import { ClassNamePropsOptional } from '@/modules/shared/ClassNameProps';
import { ServerError } from '@/modules/shared/data-access/ServerResponse';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';
import { Form } from '@/modules/shared/form/Form';
import { FormErrorList } from '@/modules/shared/form/FormErrorList';
import { ProjectsSelect } from '@/modules/app/projects/ProjectsSelect';
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/tasks/TaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ClassNamePropsOptional } from '@/modules/shared/ClassNameProps';
import { getServerSideUser } from '@/modules/app/users/UsersRepository';
import { GetTasksParams, TaskDto, getTasks } from './TasksRepository';
import { TaskListItem } from './TaskListItem';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';

export interface TaskListProps extends GetTasksParams, ClassNamePropsOptional {
readonly children?: ({
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/tasks/TasksRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createServerErrorResponse,
createServerSuccessResponse,
} from '@/modules/shared/data-access/ServerResponse';
import { genericAwareOfInternalErrorMessage } from '@/modules/app/shared/errors/errorMessages';
import { genericAwareOfInternalErrorMessage } from '@/modules/app/shared/error/errorMessages';
import { ProjectStatus } from '@/modules/app/projects/ProjectStatus';
import { TaskStatus } from './TaskStatus';
import { TaskOrderBy } from './TaskOrderBy';
Expand Down
2 changes: 1 addition & 1 deletion src/modules/app/users/UsersRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
createServerErrorResponse,
createServerSuccessResponse,
} from '@/modules/shared/data-access/ServerResponse';
import { genericAwareOfInternalErrorMessage } from '@/modules/app/shared/errors/errorMessages';
import { genericAwareOfInternalErrorMessage } from '@/modules/app/shared/error/errorMessages';

export interface UserDto {
readonly email: string;
Expand Down
29 changes: 29 additions & 0 deletions src/modules/shared/error/DefaultError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client';

import { useEffect } from 'react';
import { buttonGreenClassName } from '@/modules/shared/control/button/buttonClassName';

export const DefaultError = ({ error, reset }: { error: Error; reset: () => void }) => {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
}, [error]);

return (
<div className="mt-12 flex flex-col items-center justify-center">
<div className="flex max-w-xs flex-col items-center">
<h3 className="mb-6 text-lg font-semibold">Something went wrong!</h3>
<p className="mb-8">{error.message}</p>
<button
className={buttonGreenClassName}
onClick={
// Attempt to recover by trying to re-render the segment
() => reset()
}
>
Please try again
</button>
</div>
</div>
);
};
26 changes: 26 additions & 0 deletions src/modules/shared/error/ErrorList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import 'client-only';
import { useFormStatus } from 'react-dom';
import { twMerge } from 'tailwind-merge';
import { ClassNamePropsOptional } from '@/modules/shared/ClassNameProps';
import { ServerError } from '@/modules/shared/data-access/ServerResponse';

interface ErrorListProps extends ClassNamePropsOptional {
readonly errors: Array<ServerError>;
}

export const ErrorList = ({ className, errors }: ErrorListProps) => {
const { pending } = useFormStatus();
if (pending || !errors || errors.length < 1) return null;

return (
<div className={twMerge('flex flex-col', className)}>
{errors.map((error) => (
<p key={error.message} className="text-sm mb-2 text-red-600">
{error.message}
</p>
))}
</div>
);
};
2 changes: 1 addition & 1 deletion src/modules/shared/form/FormErrorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import 'client-only';
import { useContext } from 'react';
import { ErrorList } from '@/modules/shared/errors/ErrorList';
import { ErrorList } from '@/modules/shared/error/ErrorList';
import { FormContext } from './Form';

export const FormErrorList = () => {
Expand Down

0 comments on commit df3010b

Please sign in to comment.