-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create channel and get members, channels endpoint and hook created , …
…with create channel modal ui and jotai
- Loading branch information
Showing
15 changed files
with
290 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
## todos | ||
add reset password with email from convex password auth | ||
add reset password with email from convex password auth | ||
|
||
https://agile-toucan-670.convex.site |
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,56 @@ | ||
import Link from "next/link"; | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Id } from "../../../../convex/_generated/dataModel"; | ||
import { cva, VariantProps } from "class-variance-authority"; | ||
import { cn } from "@/lib/utils"; | ||
import { useWorkspaceId } from "@/hooks/use-workspace-id"; | ||
|
||
const UserItemVariants = cva( | ||
"flex items-center gap-1.5 justify-start font-normal h-7 px-4 text-sm overflow-hidden", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "text-[#f9edffcc]", | ||
active: "text-[#481349] bg-white/90", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
}, | ||
} | ||
); | ||
interface UserItemProps { | ||
id: Id<"members">; | ||
label?: string; | ||
image?: string; | ||
variant?: VariantProps<typeof UserItemVariants>["variant"]; | ||
} | ||
export const UserItem = ({ | ||
id, | ||
label = "Member", | ||
image, | ||
variant, | ||
}: UserItemProps) => { | ||
const workspaceId = useWorkspaceId(); | ||
const avatarFallback = label.charAt(0).toUpperCase(); | ||
console.log(id, label, image); | ||
return ( | ||
<Button | ||
variant="transparent" | ||
className={cn(UserItemVariants({ variant: variant }))} | ||
size="sm" | ||
asChild | ||
> | ||
<Link href={`/workspace/${workspaceId}/member/${id}`}> | ||
<Avatar className="size-5 rounded-md mr-1"> | ||
<AvatarImage className="rounded-md" src={image} /> | ||
<AvatarFallback className="rounded-md"> | ||
{avatarFallback} | ||
</AvatarFallback> | ||
</Avatar> | ||
<span className="text-sm truncate">{label}</span> | ||
</Link> | ||
</Button> | ||
); | ||
}; |
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,63 @@ | ||
import { useCallback, useMemo, useState } from "react"; | ||
import { Id } from "../../../../convex/_generated/dataModel"; | ||
import { useMutation } from "convex/react"; | ||
import { api } from "../../../../convex/_generated/api"; | ||
import { isSet } from "util/types"; | ||
|
||
type RequestType = { name: string; workspaceId: Id<"workspaces"> }; | ||
type ResponseType = Id<"channels"> | null; | ||
|
||
type Options = { | ||
onSuccess?: (data: ResponseType) => void; | ||
onError?: (error: Error) => void; | ||
onSettled?: () => void; | ||
throwError?: boolean; | ||
}; | ||
|
||
export const useCreateChannel = () => { | ||
const [data, setData] = useState<ResponseType>(null); | ||
const [error, setError] = useState<Error | null>(null); | ||
const [status, setStatus] = useState< | ||
"success" | "error" | "settled" | "pending" | null | ||
>(null); | ||
|
||
const isPending = useMemo(() => status === "pending", [status]); | ||
const isSuccess = useMemo(() => status === "success", [status]); | ||
const isError = useMemo(() => status === "error", [status]); | ||
const isSettled = useMemo(() => status === "settled", [status]); | ||
|
||
const mutation = useMutation(api.channels.create); | ||
|
||
const mutate = useCallback( | ||
async (values: RequestType, options?: Options) => { | ||
try { | ||
setData(null); | ||
setError(null); | ||
setStatus("pending"); | ||
const response = await mutation(values); | ||
options?.onSuccess?.(response); | ||
setStatus("success"); | ||
return response; | ||
} catch (error) { | ||
options?.onError?.(error as Error); | ||
setStatus("error"); | ||
if (options?.throwError) { | ||
throw error; | ||
} | ||
} finally { | ||
setStatus("settled"); | ||
options?.onSettled?.(); | ||
} | ||
}, | ||
[mutation] | ||
); | ||
return { | ||
mutate, | ||
data, | ||
error, | ||
isPending, | ||
isSuccess, | ||
isError, | ||
isSettled, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
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,69 @@ | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogHeader, | ||
DialogTitle, | ||
} from "@/components/ui/dialog"; | ||
import { useCreateChannelModal } from "../store/use-create-channel-modal"; | ||
import { Input } from "@/components/ui/input"; | ||
import { Button } from "@/components/ui/button"; | ||
import React, { useState } from "react"; | ||
import { useCreateChannel } from "../api/use-create-channel"; | ||
import { useWorkspaceId } from "@/hooks/use-workspace-id"; | ||
|
||
export const CreateChannelModal = () => { | ||
const workspaceId = useWorkspaceId(); | ||
const { mutate, isPending } = useCreateChannel(); | ||
|
||
const [open, setOpen] = useCreateChannelModal(); | ||
const [name, setName] = useState(""); | ||
|
||
const handleClose = () => { | ||
setName(""); | ||
setOpen(false); | ||
}; | ||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
//space here automatic turn to - | ||
const value = e.target.value.replace(/\s+/g, "-").toLocaleLowerCase(); | ||
setName(value); | ||
}; | ||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
mutate( | ||
{ name, workspaceId }, | ||
{ | ||
onSuccess: (id) => { | ||
//todo : redirect to that channel | ||
handleClose(); | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={handleClose}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Add a channel</DialogTitle> | ||
</DialogHeader> | ||
<form className="space-y-4" onSubmit={handleSubmit}> | ||
<Input | ||
value={name} | ||
disabled={isPending} | ||
onChange={handleChange} | ||
required | ||
autoFocus | ||
minLength={3} | ||
maxLength={80} | ||
placeholder="e.g. plan-budget" | ||
/> | ||
<div className="flex justify-end"> | ||
<Button className="" disabled={false}> | ||
Create | ||
</Button> | ||
</div> | ||
</form> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
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,7 @@ | ||
import { atom, useAtom } from "jotai"; | ||
|
||
const modalState = atom(false); | ||
|
||
export const useCreateChannelModal = () => { | ||
return useAtom(modalState); | ||
}; |
Oops, something went wrong.