Skip to content

Commit

Permalink
chore: use path alias for imports in web
Browse files Browse the repository at this point in the history
  • Loading branch information
aseerkt committed Jul 3, 2024
1 parent b8fc619 commit 274e53a
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 57 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ pnpm --filter e2e test:ui
pnpm --filter e2e test:codegen
```

### Unit testing

- Run web unit tests
```bash
pnpm --filter web test
```


## Features Roadmap

Expand Down
2 changes: 1 addition & 1 deletion web/src/features/auth/components/AuthFormWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logo } from '../../../components/Logo'
import { Logo } from '@/components/Logo'

interface AuthFormWrapperProps {
title: React.ReactNode
Expand Down
14 changes: 7 additions & 7 deletions web/src/features/auth/components/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Button } from '@/components/Button'
import { Input } from '@/components/Input'
import { useAuthSetter } from '@/hooks/useAuth'
import useForm from '@/hooks/useForm'
import { useToast } from '@/hooks/useToast'
import { setToken } from '@/utils/token'
import { isRequired } from '@/utils/validators'
import { useMutation } from '@tanstack/react-query'
import { NavLink } from 'react-router-dom'
import { Button } from '../../../components/Button'
import { Input } from '../../../components/Input'
import { useAuthSetter } from '../../../hooks/useAuth'
import useForm from '../../../hooks/useForm'
import { useToast } from '../../../hooks/useToast'
import { setToken } from '../../../utils/token'
import { isRequired } from '../../../utils/validators'
import { ILoginVariables, IUserResponse } from '../auth.interface'
import { login } from '../auth.service'

Expand Down
14 changes: 7 additions & 7 deletions web/src/features/auth/components/SignUpForm.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Button } from '@/components/Button'
import { Input } from '@/components/Input'
import { useAuthSetter } from '@/hooks/useAuth'
import useForm from '@/hooks/useForm'
import { useToast } from '@/hooks/useToast'
import { setToken } from '@/utils/token'
import { isRequired } from '@/utils/validators'
import { useMutation } from '@tanstack/react-query'
import { NavLink } from 'react-router-dom'
import { Button } from '../../../components/Button'
import { Input } from '../../../components/Input'
import { useAuthSetter } from '../../../hooks/useAuth'
import useForm from '../../../hooks/useForm'
import { useToast } from '../../../hooks/useToast'
import { setToken } from '../../../utils/token'
import { isRequired } from '../../../utils/validators'
import { ISignUpVariables, IUserResponse } from '../auth.interface'
import { signup } from '../auth.service'

Expand Down
1 change: 1 addition & 0 deletions web/src/features/group/components/CreateGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CreateGroupForm = ({ onComplete }: { onComplete: () => void }) => {
const navigate = useNavigate()
const inputRef = useRef<HTMLInputElement>(null)
const queryClient = useQueryClient()

const { mutate: createGroup, isPending } = useMutation({
mutationFn: createNewGroup,
onSuccess: result => {
Expand Down
10 changes: 5 additions & 5 deletions web/src/features/group/components/JoinGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Button } from '@/components/Button'
import { Dialog } from '@/components/Dialog'
import { useDisclosure } from '@/hooks/useDisclosure'
import { useToast } from '@/hooks/useToast'
import { getSocketIO } from '@/utils/socket'
import { useQueryClient } from '@tanstack/react-query'
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { Button } from '../../../components/Button'
import { Dialog } from '../../../components/Dialog'
import { useDisclosure } from '../../../hooks/useDisclosure'
import { useToast } from '../../../hooks/useToast'
import { getSocketIO } from '../../../utils/socket'
import { JoinGroupList } from './JoinGroupList'

export const JoinGroup = () => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/features/group/components/UserGroupItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cn } from '@/utils/style'
import { NavLink } from 'react-router-dom'
import { cn } from '../../../utils/style'
import { IGroup } from '../group.interface'

interface UserGroupItemProps {
Expand Down
6 changes: 3 additions & 3 deletions web/src/features/group/components/UserGroupList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Skeleton } from '@/components/Skeleton'
import { useAuthState } from '@/hooks/useAuth'
import { useInView } from '@/hooks/useInView'
import { useInfiniteQuery } from '@tanstack/react-query'
import { Fragment, useRef } from 'react'
import { Skeleton } from '../../../components/Skeleton'
import { useAuthState } from '../../../hooks/useAuth'
import { useInView } from '../../../hooks/useInView'
import { fetchUserGroups } from '../group.service'
import { UserGroupItem } from './UserGroupItem'

Expand Down
2 changes: 1 addition & 1 deletion web/src/features/group/group.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TPaginatedParams } from '../../interfaces/common.interface'
import { TPaginatedParams } from '@/interfaces/common.interface'

export interface IGroup {
id: number
Expand Down
6 changes: 2 additions & 4 deletions web/src/features/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
IPaginatedResult,
TPaginatedParams,
} from '@/interfaces/common.interface'
import { fetcher, getAuthHeaders, stringifyQueryParams } from '@/utils/api'
import { fetcher, stringifyQueryParams } from '@/utils/api'
import {
ICreateGroupArgs,
IGroup,
Expand All @@ -27,6 +27,4 @@ export const createNewGroup = async (args: ICreateGroupArgs): Promise<IGroup> =>
})

export const fetchGroup = async (groupId: number): Promise<IGroup> =>
fetcher(`groups/${groupId}`, {
headers: getAuthHeaders(),
})
fetcher(`groups/${groupId}`, {})
2 changes: 1 addition & 1 deletion web/src/features/member/components/GroupInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import backArrow from '../../../assets/back-svgrepo-com.svg'
import backArrow from '@/assets/back-svgrepo-com.svg'
import { MemberList } from './MemberList'

interface MembersListProps {
Expand Down
2 changes: 1 addition & 1 deletion web/src/features/member/components/MemberItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cn } from '../../../utils/style'
import { cn } from '@/utils/style'
import { IMember } from '../member.interface'

interface MemberItemProps {
Expand Down
10 changes: 5 additions & 5 deletions web/src/features/message/components/MessageComposer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sendSvg from '@/assets/send-svgrepo-com.svg'
import { Button } from '@/components/Button'
import { useAutoFocus } from '@/hooks/useAutoFocus'
import { useToast } from '@/hooks/useToast'
import { getSocketIO } from '@/utils/socket'
import { useRef, useState } from 'react'
import sendSvg from '../../../assets/send-svgrepo-com.svg'
import { Button } from '../../../components/Button'
import { useAutoFocus } from '../../../hooks/useAutoFocus'
import { useToast } from '../../../hooks/useToast'
import { getSocketIO } from '../../../utils/socket'

interface MessageComposerProps {
groupId: number
Expand Down
4 changes: 2 additions & 2 deletions web/src/features/message/components/MessageItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formateChatDate } from '../../../utils/date'
import { cn } from '../../../utils/style'
import { formateChatDate } from '@/utils/date'
import { cn } from '@/utils/style'
import { IMessage } from '../message.interface'

interface MessageItemProps {
Expand Down
10 changes: 5 additions & 5 deletions web/src/layouts/ChatLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PageLoader } from '@/components/PageLoader'
import { ChatHeader } from '@/features/chat/components'
import { ChatUser } from '@/features/chat/components/ChatUser'
import { CreateGroup, GroupList, JoinGroup } from '@/features/group/components'
import { useSocketConnect } from '@/hooks/useSocketConnect'
import { cn } from '@/utils/style'
import { Outlet, useParams } from 'react-router-dom'
import { PageLoader } from '../components/PageLoader'
import { ChatHeader } from '../features/chat/components'
import { ChatUser } from '../features/chat/components/ChatUser'
import { useSocketConnect } from '../hooks/useSocketConnect'
import { cn } from '../utils/style'

const ChatLayout = () => {
const { isConnected } = useSocketConnect()
Expand Down
18 changes: 4 additions & 14 deletions web/src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
import { config } from '../config'
import { getToken } from './token'

export const getAuthHeaders = () => {
const token = getToken()
return {
'Content-Type': 'application/json',
Authorization: token ? `Bearer ${token}` : '',
}
}

export const getUrl = (path: string) => {
return `${config.backendUrl}/api/${path}`
}

export const stringifyQueryParams = <
TQueryParams extends Record<string, unknown>,
>(
Expand All @@ -29,10 +17,12 @@ export const stringifyQueryParams = <
}

export const fetcher = async (path: string, options?: RequestInit) => {
const res = await fetch(getUrl(path), {
const token = getToken()
const res = await fetch(`${config.backendUrl}/api/${path}`, {
...options,
headers: {
...getAuthHeaders(),
'Content-Type': 'application/json',
Authorization: token ? `Bearer ${token}` : '',
...options?.headers,
},
})
Expand Down

0 comments on commit 274e53a

Please sign in to comment.