Skip to content

Commit

Permalink
chore: update project dir structure
Browse files Browse the repository at this point in the history
References: #49, #51

Signed-off-by: Prince Muel <[email protected]>
  • Loading branch information
princemuel committed May 8, 2023
1 parent fb7aeed commit 44ddfeb
Show file tree
Hide file tree
Showing 47 changed files with 120 additions and 103 deletions.
3 changes: 1 addition & 2 deletions src/components/atoms/avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useAuthState } from '@src/context';
import { trim } from '@src/helpers';
import { trim, useAuthState } from '@src/lib';

interface Props {
src?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/form-label.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx';
import React from 'react';
import * as React from 'react';

interface Props
extends React.DetailedHTMLProps<
Expand Down
6 changes: 2 additions & 4 deletions src/components/atoms/logout-button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { IErrorResponse } from '@src/@types';
import { useAuthDispatch } from '@src/context';
import { useLogoutQuery } from '@src/hooks';
import { client } from '@src/lib';
import { client, useAuthDispatch, useLogoutQuery } from '@src/lib';
import { useQueryClient } from '@tanstack/react-query';
import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -34,7 +32,7 @@ const LogoutButton = (props: Props) => {

const logout = useCallback(() => {
refetch();
}, []);
}, [refetch]);

return (
<button type='button' onClick={logout}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/status-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize } from '@src/helpers';
import { capitalize } from '@src/lib';
import clsx from 'clsx';

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/theme-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useSetTheme, useTheme } from '@src/context';
import { useSetTheme, useTheme } from '@src/lib';
import { clsx } from 'clsx';

const ThemeButton = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/actions-btns.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InvoiceType } from '@src/hooks';
import type { InvoiceType } from '@src/lib';
import clsx from 'clsx';
import { Link } from 'react-router-dom';

Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Menu, Transition } from '@headlessui/react';
import { icons } from '@src/common';
import { DateTime, datetime } from '@src/helpers';
import { DateTime, datetime } from '@src/lib';
import clsx from 'clsx';
import { Dayjs } from 'dayjs';
import * as React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Listbox, Transition } from '@headlessui/react';
import { icons } from '@src/common';
import { pluralize } from '@src/helpers';
import { pluralize } from '@src/lib';
import { Dispatch, Fragment, SetStateAction } from 'react';

interface Props {
Expand Down
5 changes: 2 additions & 3 deletions src/components/molecules/edit-item-list.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { calculateTotal, endsWith } from '@src/helpers';
import { useMedia } from '@src/hooks';
import { calculateTotal, endsWith, useMedia } from '@src/lib';
import clsx from 'clsx';
import * as React from 'react';
import {
Expand All @@ -10,7 +9,7 @@ import {
} from 'react-hook-form';
import { v4 as uuid } from 'uuid';
import { FormErrorText, FormLabel } from '../atoms';
import { InvoiceFormType } from './@types';
import type { InvoiceFormType } from './@types';
import { PriceOutput } from './price-output';

interface Props {
Expand Down
8 changes: 6 additions & 2 deletions src/components/molecules/invoice-item-details.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { calculateTotal, formatPrice } from '@src/helpers';
import { InvoiceItemType, useMedia } from '@src/hooks';
import {
InvoiceItemType,
calculateTotal,
formatPrice,
useMedia,
} from '@src/lib';
import clsx from 'clsx';
import * as React from 'react';
import { Text } from '../atoms';
Expand Down
3 changes: 1 addition & 2 deletions src/components/molecules/new-item-list.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { calculateTotal, endsWith } from '@src/helpers';
import { useMedia } from '@src/hooks';
import { calculateTotal, endsWith, useMedia } from '@src/lib';
import clsx from 'clsx';
import * as React from 'react';
import {
Expand Down
10 changes: 4 additions & 6 deletions src/components/organisms/edit-invoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import {
InvoiceFormSchema,
RHFSubmitHandler,
calculateTotal,
constants,
client,
hasValues,
terms,
useZodForm,
} from '@src/helpers';
import {
useGetInvoiceQuery,
useGetInvoicesQuery,
useUpdateInvoiceMutation,
} from '@src/hooks';
import { client } from '@src/lib';
useZodForm,
constants,
} from '@src/lib';
import { useQueryClient } from '@tanstack/react-query';
import { produce } from 'immer';
import { useState } from 'react';
Expand Down
3 changes: 1 addition & 2 deletions src/components/organisms/invoice-details.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { datetime } from '@src/helpers';
import { InvoiceType, useMedia } from '@src/hooks';
import { InvoiceType, datetime, useMedia } from '@src/lib';
import * as React from 'react';
import { BackLink, StatusButton, Text } from '../atoms';
import { InvoiceActions, InvoiceItemDetails } from '../molecules';
Expand Down
9 changes: 6 additions & 3 deletions src/components/organisms/login.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { IErrorResponse } from '@src/@types';
import { icons } from '@src/common';
import { LoginFormSchema, RHFSubmitHandler, useZodForm } from '@src/helpers';
import { useLoginMutation, usePersist } from '@src/hooks';
import { client } from '@src/lib';
import { client, useLoginMutation, usePersist } from '@src/lib';
import {
LoginFormSchema,
RHFSubmitHandler,
useZodForm,
} from '@src/lib/helpers';
import { FormProvider } from 'react-hook-form';
import { Link, useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify';
Expand Down
9 changes: 5 additions & 4 deletions src/components/organisms/new-invoice.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { InvoiceStatus } from '@src/@types';
import { useAuthState } from '@src/context';
import {
DateTime,
InvoiceFormSchema,
RHFSubmitHandler,
calculateTotal,
client,
constants,
terms,
useAuthState,
useCreateInvoiceMutation,
useGetInvoicesQuery,
useZodForm,
} from '@src/helpers';
import { useCreateInvoiceMutation, useGetInvoicesQuery } from '@src/hooks';
import { client } from '@src/lib';
} from '@src/lib';
import { useQueryClient } from '@tanstack/react-query';
import { produce } from 'immer';
import { useEffect, useState } from 'react';
Expand Down
10 changes: 7 additions & 3 deletions src/components/organisms/register.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { IErrorResponse } from '@src/@types';
import { RHFSubmitHandler, RegisterFormSchema, useZodForm } from '@src/helpers';
import { useRegisterMutation } from '@src/hooks';
import { client } from '@src/lib';
import {
RHFSubmitHandler,
RegisterFormSchema,
client,
useRegisterMutation,
useZodForm,
} from '@src/lib';
import { FormProvider } from 'react-hook-form';
import { Link, useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify';
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Avatar, Logo, ThemeButton } from '../atoms';

type Props = {};
interface Props {}

const Sidebar = (props: Props) => {
return (
Expand Down
13 changes: 9 additions & 4 deletions src/components/templates/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import {
EnvelopeOpenIcon,
InboxArrowDownIcon,
} from '@heroicons/react/24/solid';
import { IStatus } from '@src/@types';
import { datetime, formatPrice, hasValues, pluralize } from '@src/helpers';
import { useGetInvoicesQuery } from '@src/hooks';
import { client } from '@src/lib';
import type { IStatus } from '@src/@types';
import {
client,
datetime,
formatPrice,
hasValues,
pluralize,
useGetInvoicesQuery,
} from '@src/lib';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { StatusButton, Text } from '../atoms';
Expand Down
4 changes: 2 additions & 2 deletions src/components/templates/invoice.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Dialog, Transition } from '@headlessui/react';
import {
InvoiceType,
client,
useDeleteInvoiceMutation,
useGetInvoiceQuery,
useGetInvoicesQuery,
useUpdateInvoiceMutation,
} from '@src/hooks';
import { client } from '@src/lib';
} from '@src/lib';
import { useQueryClient } from '@tanstack/react-query';
import { Fragment, useCallback, useRef, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
Expand Down
7 changes: 4 additions & 3 deletions src/components/templates/invoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import type { IStatus } from '@src/@types';
import { icons } from '@src/common';
import {
capitalize,
client,
datetime,
formatPrice,
hasValues,
reverse,
statuses,
trim,
} from '@src/helpers';
import { useGetInvoicesQuery, useMedia } from '@src/hooks';
import { client } from '@src/lib';
useGetInvoicesQuery,
useMedia,
} from '@src/lib';
import { Fragment, useState } from 'react';
import { Link } from 'react-router-dom';
import { StatusButton, Text } from '../atoms';
Expand Down
2 changes: 1 addition & 1 deletion src/components/templates/seo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { constants } from '@src/helpers';
import { constants } from '@src/lib';
import * as React from 'react';
import { Helmet } from 'react-helmet-async';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/client/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { constants } from '@src/helpers';
import { GraphQLClient } from 'graphql-request';
import { constants } from '../helpers';

const endpoint = `${constants.BASE_URL}`; // process?.env?.NEXT_PUBLIC_GRAPHQL_ENDPOINT ??

Expand Down
4 changes: 2 additions & 2 deletions src/context/auth.tsx → src/lib/context/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IUser } from '@src/@types';
import { produce } from 'immer';
import {
Dispatch,
Expand All @@ -7,9 +8,8 @@ import {
useMemo,
useReducer,
} from 'react';
import type { IUser } from '../@types';
import { client } from '../client';
import { useGetUserQuery, useRefreshAuthQuery } from '../hooks';
import { client } from '../lib';
interface IState {
token?: string;
user?: Partial<IUser>;
Expand Down
File renamed without changes.
File renamed without changes.
48 changes: 24 additions & 24 deletions src/context/modal.tsx → src/lib/context/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,35 @@ const initialState: IModalState = {
current: null,
};

const reducer = (state: IModalState, action: IModalActions) => {
switch (action.type) {
case 'OPEN_MODAL':
return {
...state,
open: true,
current: action.payload.id,
};
case 'CLOSE_MODAL':
return {
...state,
open: false,
current: null,
};
default: {
//@ts-expect-error ignore ts-error
throw new Error(`Unhandled action type: ${action.type}`);
}
}
};

const Store = createContext<IModalState | null>(null);
const StoreDispatch = createContext<Dispatch<IModalActions> | null>(null);

type ProviderProps = {
interface Props {
children: ReactNode;
};
}

export const ModalProvider = ({ children }: ProviderProps) => {
export const ModalProvider = ({ children }: Props) => {
const [state, dispatch] = useReducer(reducer, initialState);

return (
Expand All @@ -57,24 +78,3 @@ export const useModalDispatch = () => {
throw new Error('useModalDispatch must be used within a ModalProvider');
return context;
};

const reducer = (state: IModalState, action: IModalActions) => {
switch (action.type) {
case 'OPEN_MODAL':
return {
...state,
open: true,
current: action.payload.id,
};
case 'CLOSE_MODAL':
return {
...state,
open: false,
current: null,
};
default: {
//@ts-expect-error
throw new Error(`Unhandled action type: ${action.type}`);
}
}
};
6 changes: 3 additions & 3 deletions src/context/theme.tsx → src/lib/context/theme.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { off, on } from '@src/helpers';
import * as React from 'react';
import { off, on } from '../helpers';

type ThemeMode = 'dark' | 'light';
type ThemeState = ReturnType<typeof useThemeMode>[0] | null;
Expand All @@ -8,9 +8,9 @@ type SetThemeState = ReturnType<typeof useThemeMode>[1] | null;
const ThemeContext = React.createContext<ThemeState>(null);
const SetThemeContext = React.createContext<SetThemeState>(null);

type Props = {
interface Props {
children: React.ReactNode;
};
}

const ThemeProvider = ({ children }: Props) => {
const [mode, setMode] = useThemeMode();
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions src/helpers/datetime.ts → src/lib/helpers/datetime.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { uuid } from '@src/common';
import dayjs from 'dayjs';
import dayjs, { extend } from 'dayjs';
import LocaleData from 'dayjs/plugin/localeData';
import UTC from 'dayjs/plugin/utc';

dayjs.extend(LocaleData);
dayjs.extend(UTC);
extend(LocaleData);
extend(UTC);

interface IDay {
id: ReturnType<typeof uuid>;
date: dayjs.Dayjs;
Expand All @@ -17,8 +18,6 @@ export class DateTime {
static MONTHS = dayjs.monthsShort();
static TODAY = dayjs.utc();

constructor() {}

private uuid() {
return uuid();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
type ErrorWithMessage = {
interface ErrorWithMessage {
message: string;
};
type ErrorDataWithMessage = { data: { message: string } };
}
interface ErrorDataWithMessage {
data: { message: string };
}

export function getErrorMessage(error: unknown) {
return toErrorWithMessage(error).message;
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 44ddfeb

Please sign in to comment.