-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Dev #7
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
643fb3d
feat: added better navbar styling
BuckyMcYolo 9733226
feat: added onboarding popup dialog flow with Townhall Image
BuckyMcYolo 8ca6f42
fix: Set permissive CORS policy for API server
BuckyMcYolo 83ae698
feat: fix CORS origin issues and other various minor issues
BuckyMcYolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
285 changes: 285 additions & 0 deletions
285
apps/web/src/components/onboarding/onboarding-dialog.tsx
This file contains hidden or 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,285 @@ | ||
| "use client" | ||
|
|
||
| import { authClient } from "@repo/auth/client" | ||
| import { Button } from "@repo/ui/components/button" | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@repo/ui/components/dialog" | ||
| import { Input } from "@repo/ui/components/input" | ||
| import { Label } from "@repo/ui/components/label" | ||
| import { useQueryClient } from "@tanstack/react-query" | ||
| import { useNavigate } from "@tanstack/react-router" | ||
| import { ArrowLeft, Loader2, Plus, Users } from "lucide-react" | ||
| import { useEffect, useState } from "react" | ||
|
|
||
| type Step = "welcome" | "create" | "join" | ||
|
|
||
| function toSlug(name: string) { | ||
| return name | ||
| .toLowerCase() | ||
| .trim() | ||
| .replace(/[^a-z0-9\s-]/g, "") | ||
| .replace(/\s+/g, "-") | ||
| .replace(/-+/g, "-") | ||
| .replace(/^-+|-+$/g, "") | ||
| .slice(0, 50) | ||
| } | ||
|
|
||
| export function OnboardingDialog({ open }: { open: boolean }) { | ||
| const [step, setStep] = useState<Step>("welcome") | ||
| const [name, setName] = useState("") | ||
| const [slug, setSlug] = useState("") | ||
| const [slugEdited, setSlugEdited] = useState(false) | ||
| const [inviteLink, setInviteLink] = useState("") | ||
| const [error, setError] = useState<string | null>(null) | ||
| const [loading, setLoading] = useState(false) | ||
| const queryClient = useQueryClient() | ||
| const navigate = useNavigate() | ||
|
|
||
| useEffect(() => { | ||
| if (!slugEdited) { | ||
| setSlug(toSlug(name)) | ||
| } | ||
| }, [name, slugEdited]) | ||
|
|
||
| const handleCreate = async (e: React.FormEvent) => { | ||
| e.preventDefault() | ||
| if (!name.trim() || !slug.trim()) return | ||
| setError(null) | ||
| setLoading(true) | ||
|
|
||
| try { | ||
| const res = await authClient.organization.create({ | ||
| name: name.trim(), | ||
| slug: slug.trim(), | ||
| }) | ||
|
|
||
| if (res.error) { | ||
| setError(res.error.message ?? "Failed to create guild") | ||
| setLoading(false) | ||
| return | ||
| } | ||
|
|
||
| // Best-effort — guild was created successfully so proceed regardless | ||
| try { | ||
| await authClient.updateUser({ onboardingCompleted: true }) | ||
| } catch { | ||
| // Non-blocking: dialog will reappear next session but guild exists | ||
| setError("Guild created, but failed to save onboarding state.") | ||
| } | ||
|
|
||
| await queryClient.invalidateQueries({ queryKey: ["guilds"] }) | ||
| navigate({ to: "/$guildSlug", params: { guildSlug: slug.trim() } }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } catch { | ||
| setError("Something went wrong. Please try again.") | ||
| setLoading(false) | ||
| } | ||
| } | ||
|
BuckyMcYolo marked this conversation as resolved.
|
||
|
|
||
| const handleJoin = async (e: React.FormEvent) => { | ||
| e.preventDefault() | ||
| if (!inviteLink.trim()) return | ||
| setError(null) | ||
| setLoading(true) | ||
| // TODO: implement join via invite link API | ||
| setError("Joining via invite link is not yet supported.") | ||
| setLoading(false) | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog open={open}> | ||
| <DialogContent | ||
| showCloseButton={false} | ||
| onInteractOutside={(e) => e.preventDefault()} | ||
| onEscapeKeyDown={(e) => e.preventDefault()} | ||
| className="overflow-hidden p-0 sm:max-w-2xl" | ||
| > | ||
| <div className="flex min-h-[460px]"> | ||
| {/* Left decorative panel */} | ||
| <div className="relative hidden w-[220px] shrink-0 overflow-hidden sm:block"> | ||
| <img | ||
| src="/townhall-onboarding2.png" | ||
| alt="A medieval campsite at night" | ||
| className="absolute inset-0 h-full w-full object-cover" | ||
| /> | ||
| </div> | ||
|
|
||
| {/* Right content panel */} | ||
| <div className="flex flex-1 flex-col justify-center p-8"> | ||
| {step === "welcome" && ( | ||
| <> | ||
| <DialogHeader className="mb-8 text-left"> | ||
| <DialogTitle className="text-2xl"> | ||
| Welcome to Townhall | ||
| </DialogTitle> | ||
| <DialogDescription className="text-sm"> | ||
| Get started by creating a new guild or joining one you've | ||
| been invited to. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <div className="space-y-3"> | ||
| <button | ||
| type="button" | ||
| onClick={() => setStep("create")} | ||
| className="group flex w-full items-center gap-4 rounded-lg border border-border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent" | ||
| > | ||
| <div className="flex size-10 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary group-hover:bg-primary/20"> | ||
| <Plus className="size-5" /> | ||
| </div> | ||
| <div> | ||
| <p className="font-medium">Create a Guild</p> | ||
| <p className="text-sm text-muted-foreground"> | ||
| Start your own community from scratch | ||
| </p> | ||
| </div> | ||
| </button> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={() => setStep("join")} | ||
| className="group flex w-full items-center gap-4 rounded-lg border border-border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent" | ||
| > | ||
| <div className="flex size-10 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary group-hover:bg-primary/20"> | ||
| <Users className="size-5" /> | ||
| </div> | ||
| <div> | ||
| <p className="font-medium">Join an Existing Guild</p> | ||
| <p className="text-sm text-muted-foreground"> | ||
| Enter an invite link to join a guild | ||
| </p> | ||
| </div> | ||
| </button> | ||
| </div> | ||
| </> | ||
| )} | ||
|
|
||
| {step === "create" && ( | ||
| <> | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| setStep("welcome") | ||
| setError(null) | ||
| }} | ||
| className="mb-6 flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground" | ||
| > | ||
| <ArrowLeft className="size-3.5" /> | ||
| Back | ||
| </button> | ||
|
|
||
| <DialogHeader className="mb-6 text-left"> | ||
| <DialogTitle className="text-2xl">Create a Guild</DialogTitle> | ||
| <DialogDescription className="text-sm"> | ||
| Give your community a name and a unique URL. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <form onSubmit={handleCreate} className="space-y-4"> | ||
| <div className="space-y-1.5"> | ||
| <Label htmlFor="guild-name">Guild Name</Label> | ||
| <Input | ||
| id="guild-name" | ||
| placeholder="My Awesome Guild" | ||
| value={name} | ||
| onChange={(e) => setName(e.target.value)} | ||
| disabled={loading} | ||
| autoFocus | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="space-y-1.5"> | ||
| <Label htmlFor="guild-slug">Slug</Label> | ||
| <div className="flex items-center rounded-md border border-input bg-muted px-3 text-sm focus-within:ring-1 focus-within:ring-ring"> | ||
| <span className="shrink-0 text-muted-foreground"> | ||
| townhall.chat/ | ||
| </span> | ||
| <Input | ||
| id="guild-slug" | ||
| className="min-w-0 flex-1 border-0 bg-transparent shadow-none focus-visible:ring-0 px-1" | ||
| placeholder="my-awesome-guild" | ||
| value={slug} | ||
| onChange={(e) => { | ||
| setSlugEdited(true) | ||
| setSlug(toSlug(e.target.value)) | ||
| }} | ||
| disabled={loading} | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| {error && <p className="text-sm text-destructive">{error}</p>} | ||
|
|
||
| <Button | ||
| type="submit" | ||
| className="w-full" | ||
| disabled={loading || !name.trim() || !slug.trim()} | ||
| > | ||
| {loading && ( | ||
| <Loader2 className="mr-2 size-4 animate-spin" /> | ||
| )} | ||
| Create Guild | ||
| </Button> | ||
| </form> | ||
| </> | ||
| )} | ||
|
|
||
| {step === "join" && ( | ||
| <> | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| setStep("welcome") | ||
| setError(null) | ||
| }} | ||
| className="mb-6 flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground" | ||
| > | ||
| <ArrowLeft className="size-3.5" /> | ||
| Back | ||
| </button> | ||
|
|
||
| <DialogHeader className="mb-6 text-left"> | ||
| <DialogTitle className="text-2xl">Join a Guild</DialogTitle> | ||
| <DialogDescription className="text-sm"> | ||
| Paste an invite link to join an existing guild. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <form onSubmit={handleJoin} className="space-y-4"> | ||
| <div className="space-y-1.5"> | ||
| <Label htmlFor="invite-link">Invite Link</Label> | ||
| <Input | ||
| id="invite-link" | ||
| placeholder="https://townhall.gg/invite/abc123" | ||
| value={inviteLink} | ||
| onChange={(e) => setInviteLink(e.target.value)} | ||
| disabled={loading} | ||
| autoFocus | ||
| /> | ||
| </div> | ||
|
|
||
| {error && <p className="text-sm text-destructive">{error}</p>} | ||
|
|
||
| <Button | ||
| type="submit" | ||
| className="w-full" | ||
| disabled={loading || !inviteLink.trim()} | ||
| > | ||
| {loading && ( | ||
| <Loader2 className="mr-2 size-4 animate-spin" /> | ||
| )} | ||
| Join Guild | ||
| </Button> | ||
| </form> | ||
| </> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ) | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.