forked from ravi2611gupta/next13-whatsapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ec6089
commit 6e804ca
Showing
18 changed files
with
1,115 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use client'; | ||
|
||
import { classNames } from "../helpers"; | ||
import { User } from "@prisma/client"; | ||
|
||
interface AvatarGroupProps { | ||
users?: User[]; | ||
large?: boolean; | ||
}; | ||
|
||
const AvatarGroup: React.FC<AvatarGroupProps> = ({ users = [], large }) => { | ||
const slicedUsers = users.slice(0, 3); | ||
|
||
const positionMap = { | ||
0: 'top-0 left-[12px]', | ||
1: 'bottom-0', | ||
2: 'bottom-0 right-0' | ||
} | ||
|
||
return ( | ||
<div className="relative h-11 w-11"> | ||
{slicedUsers.map((user, index) => ( | ||
<div | ||
key={user.id} | ||
className={` | ||
absolute | ||
inline-block | ||
rounded-full | ||
overflow-hidden | ||
h-[21px] | ||
w-[21px] | ||
${positionMap[index as keyof typeof positionMap]} | ||
`}> | ||
<img | ||
src={user?.imageUrl || '/images/placeholder.jpg'} | ||
alt="" | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default AvatarGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
'use client'; | ||
|
||
import React from 'react' | ||
import { useRouter } from 'next/navigation'; | ||
import AuthInput from '@/app/(site)/components/AuthInput'; | ||
import { FieldValues, SubmitHandler, useForm } from 'react-hook-form'; | ||
import Modal from './Modal'; | ||
import { User } from '@prisma/client'; | ||
import axios from 'axios'; | ||
import Select from './Select'; | ||
|
||
interface GroupChatModalProps { | ||
isOpen?: boolean; | ||
onClose: () => void; | ||
users: User[]; | ||
} | ||
|
||
const GroupChatModal: React.FC<GroupChatModalProps> = ({ isOpen, onClose, users = [] }) => { | ||
const router = useRouter(); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
setValue, | ||
watch, | ||
formState: { | ||
errors, | ||
} | ||
} = useForm<FieldValues>({ | ||
defaultValues: { | ||
name: '', | ||
members: [] | ||
} | ||
}); | ||
|
||
const members = watch('members'); | ||
|
||
const onSubmit: SubmitHandler<FieldValues> = (data) => { | ||
axios.post('/api/conversations', { | ||
...data, | ||
isGroup: true | ||
}) | ||
.then(() => { | ||
router.refresh(); | ||
onClose(); | ||
}) | ||
} | ||
|
||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<div className="space-y-12"> | ||
<div className="border-b border-gray-900/10 pb-12"> | ||
<h2 className="text-base font-semibold leading-7 text-gray-900">Create a group chat</h2> | ||
<p className="mt-1 text-sm leading-6 text-gray-600"> | ||
Create a chat with more than 2 people. | ||
</p> | ||
<div className="mt-10 flex flex-col gap-y-8"> | ||
<AuthInput | ||
label="Name" | ||
id="name" | ||
errors={errors} | ||
required | ||
register={register} | ||
/> | ||
<Select | ||
label="Members" | ||
options={users.map((user) => ({ value: user.id, label: user.name }))} | ||
onChange={(value) => setValue('members', value, { shouldValidate: true })} | ||
value={members} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="mt-6 flex items-center justify-end gap-x-6"> | ||
<button onClick={onClose} type="button" className="text-sm font-semibold leading-6 text-gray-900"> | ||
Cancel | ||
</button> | ||
<button | ||
type="submit" | ||
className="rounded-md bg-sky-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-sky-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-600" | ||
> | ||
Create | ||
</button> | ||
</div> | ||
</form> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default GroupChatModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import ReactSelect from 'react-select' | ||
|
||
interface SelectProps { | ||
label: string; | ||
value?: Record<string, any>; | ||
onChange: (value: Record<string, any>) => void; | ||
options: Record<string, any>[]; | ||
} | ||
|
||
const Select: React.FC<SelectProps> = ({ | ||
label, | ||
value, | ||
onChange, | ||
options | ||
}) => { | ||
return ( | ||
<div> | ||
<label | ||
className=" | ||
block | ||
text-sm | ||
font-medium | ||
leading-6 | ||
text-gray-900 | ||
" | ||
> | ||
{label} | ||
</label> | ||
<div className="mt-2"> | ||
<ReactSelect | ||
value={value} | ||
onChange={onChange} | ||
isMulti | ||
options={options} | ||
classNames={{ | ||
control: () => 'text-sm', | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Select; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.