Skip to content

Commit

Permalink
feat: join group form if not joined in any group
Browse files Browse the repository at this point in the history
  • Loading branch information
aseerkt committed Aug 11, 2024
1 parent c199f56 commit b249b03
Show file tree
Hide file tree
Showing 11 changed files with 749 additions and 645 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
"author": "Aseer KT",
"license": "ISC",
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/cli": "^19.4.0",
"@commitlint/config-conventional": "^19.2.2",
"husky": "^8.0.3",
"typescript": "^5.5.3"
"typescript": "^5.5.4"
},
"workspaces": [
"client",
Expand Down
1,342 changes: 718 additions & 624 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"start": "node dist/index.js",
"dev": "tsx watch src/index.ts",
"dev": "NO_ALIAS=true tsx watch src/index.ts",
"build": "tsc",
"lint": "tsc && eslint src/**/*.ts",
"migrate:gen": "drizzle-kit generate",
Expand All @@ -21,6 +21,7 @@
"author": "Aseer KT",
"license": "ISC",
"dependencies": {
"@faker-js/faker": "^8.4.1",
"@socket.io/redis-streams-adapter": "^0.2.2",
"argon2": "^0.40.3",
"colors": "^1.4.0",
Expand All @@ -39,29 +40,26 @@
"socket.io": "^4.7.5",
"swagger-autogen": "^2.23.7",
"swagger-ui-express": "^5.0.1",
"uuid": "^10.0.0",
"@faker-js/faker": "^8.4.1"
"uuid": "^10.0.0"
},
"devDependencies": {
"drizzle-kit": "^0.22.8",
"@eslint/js": "^9.6.0",
"@types/cookie-parser": "^1.4.7",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.6",
"@types/lodash": "^4.17.6",
"@types/module-alias": "^2.0.4",
"@types/morgan": "^1.9.9",
"@types/node": "^20.14.5",
"@types/pg": "^8.11.6",
"@types/swagger-ui-express": "^4.1.6",
"@types/uuid": "^10.0.0",
"drizzle-kit": "^0.22.8",
"eslint": "9.x",
"globals": "^15.7.0",
"tsx": "^4.15.6",
"typescript": "^5.5.3",
"typescript-eslint": "^7.15.0"
},
"_moduleAliases": {
"@": "dist"
}
}
5 changes: 2 additions & 3 deletions server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'module-alias/register'
import './utils/loadModules'

import { createAdapter } from '@socket.io/redis-streams-adapter'
import 'colors'
Expand Down Expand Up @@ -41,14 +41,13 @@ const createApp = async () => {
express.json(),
helmet(),
morgan(config.isProd ? 'combined' : 'dev'),
cookieParser(),
)

if (!config.isProd) {
app.use(cors({ origin: config.corsOrigin, credentials: true }))
}

app.use(cookieParser())

const server = createServer(app)

const io = new Server<
Expand Down
1 change: 1 addition & 0 deletions server/src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const signUpUser: RequestHandler = async (req, res, next) => {

export const loginUser: RequestHandler = async (req, res, next) => {
try {
console.log('got into login controller')
const { username, password } = req.body
const [user] = await db
.select()
Expand Down
2 changes: 1 addition & 1 deletion server/src/scripts/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'module-alias/register'
import '../utils/loadModules'

import 'colors'
import { migrate } from 'drizzle-orm/node-postgres/migrator'
Expand Down
2 changes: 1 addition & 1 deletion server/src/scripts/seed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'module-alias/register'
import '../utils/loadModules'

import { connectDB, db } from '@/database'
import { NewGroup, groupsTable } from '@/modules/groups/groups.schema'
Expand Down
2 changes: 1 addition & 1 deletion server/src/scripts/swagger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'module-alias/register'
import '../utils/loadModules'

import swaggerAutogen from 'swagger-autogen'

Expand Down
6 changes: 6 additions & 0 deletions server/src/utils/loadModules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import moduleAlias from 'module-alias'
import path from 'node:path'

if (!process.env.NO_ALIAS) {
moduleAlias.addAliases({ '@': path.resolve(__dirname, '..', '..', 'dist') })
}
11 changes: 6 additions & 5 deletions web/src/features/group/components/JoinGroupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { useNavigate } from 'react-router-dom'
import { joinGroups } from '../group.service'
import { JoinGroupList } from './JoinGroupList'

export const JoinGroupsForm = ({ onComplete }: { onComplete: () => void }) => {
export const JoinGroupsForm = ({
onComplete = () => {},
}: {
onComplete?: () => void
}) => {
const { toast } = useToast()
const navigate = useNavigate()
const queryClient = useQueryClient()
Expand Down Expand Up @@ -42,10 +46,7 @@ export const JoinGroupsForm = ({ onComplete }: { onComplete: () => void }) => {
}

return (
<form
onSubmit={handleSubmit}
className='flex h-[400px] min-w-[350px] flex-col'
>
<form onSubmit={handleSubmit} className='flex h-[400px] flex-col'>
<header className='mb-3 px-6'>
<h3 className='text-xl font-semibold'>Select groups to join</h3>
</header>
Expand Down
7 changes: 6 additions & 1 deletion web/src/features/group/components/UserChatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useInfiniteQuery } from '@tanstack/react-query'
import { Fragment, useRef } from 'react'
import { fetchUserGroups } from '../group.service'
import { useChatSocketHandle } from '../hooks/useChatSocketHandle'
import { JoinGroupsForm } from './JoinGroupForm'
import { UserChatItem } from './UserChatItem'

export const UserChatList = () => {
Expand Down Expand Up @@ -55,7 +56,11 @@ export const UserChatList = () => {
</ul>
)
} else if (isSuccess) {
content = <Alert severity='info'>Join or create group</Alert>
content = (
<div className='px-3 py-4'>
<JoinGroupsForm />
</div>
)
}

return <aside className='flex-1 overflow-hidden'>{content}</aside>
Expand Down

0 comments on commit b249b03

Please sign in to comment.