-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v3-main' into add-guild-page
- Loading branch information
Showing
62 changed files
with
1,683 additions
and
147 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
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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,19 @@ | ||
"use server"; | ||
|
||
import { pinata } from "@/config/pinata.server"; | ||
|
||
export const getPinataKey = async () => { | ||
const uuid = crypto.randomUUID(); | ||
const keyData = await pinata.keys.create({ | ||
keyName: uuid.toString(), | ||
permissions: { | ||
endpoints: { | ||
pinning: { | ||
pinFileToIPFS: true, | ||
}, | ||
}, | ||
}, | ||
maxUses: 1, | ||
}); | ||
return keyData; | ||
}; |
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,27 @@ | ||
import type { Metadata } from "next"; | ||
|
||
type Props = { | ||
params: Promise<{ guild: string }>; | ||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>; | ||
}; | ||
|
||
export async function generateMetadata({ params }: Props): Promise<Metadata> { | ||
const urlName = (await params).guild; | ||
|
||
return { | ||
title: urlName, | ||
}; | ||
} | ||
|
||
const GuildPage = async ({ params }: Props) => { | ||
const urlName = (await params).guild; | ||
|
||
return ( | ||
<div className="grid gap-4"> | ||
<p>Guild page</p> | ||
<p>{`URL name: ${urlName}`}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GuildPage; |
80 changes: 80 additions & 0 deletions
80
src/app/(dashboard)/create-guild/components/CreateGuildButton.tsx
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,80 @@ | ||
"use client"; | ||
|
||
import { useConfetti } from "@/components/ConfettiProvider"; | ||
import { Button } from "@/components/ui/Button"; | ||
import { GUILD_AUTH_COOKIE_NAME } from "@/config/constants"; | ||
import { env } from "@/lib/env"; | ||
import { fetcher } from "@/lib/fetcher"; | ||
import { getCookie } from "@/lib/getCookie"; | ||
import type { CreateGuildForm, Guild } from "@/lib/schemas/guild"; | ||
import { CheckCircle, XCircle } from "@phosphor-icons/react/dist/ssr"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { useRouter } from "next/navigation"; | ||
import { useFormContext } from "react-hook-form"; | ||
import slugify from "slugify"; | ||
import { toast } from "sonner"; | ||
|
||
const CreateGuildButton = () => { | ||
const { handleSubmit } = useFormContext<CreateGuildForm>(); | ||
|
||
const confetti = useConfetti(); | ||
|
||
const router = useRouter(); | ||
|
||
const { mutate: onSubmit, isPending } = useMutation({ | ||
mutationFn: async (data: CreateGuildForm) => { | ||
const token = getCookie(GUILD_AUTH_COOKIE_NAME); | ||
|
||
if (!token) throw new Error("Unauthorized"); // TODO: custom errors? | ||
|
||
const guild = { | ||
...data, | ||
contact: undefined, | ||
// TODO: I think we should do it on the backend | ||
urlName: slugify(data.name, { | ||
replacement: "-", | ||
lower: true, | ||
strict: true, | ||
}), | ||
}; | ||
|
||
return fetcher<Guild>(`${env.NEXT_PUBLIC_API}/guild`, { | ||
method: "POST", | ||
headers: { | ||
"X-Auth-Token": token, | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(guild), | ||
}); | ||
}, | ||
onError: (error) => { | ||
// TODO: parse the error and display it in a user-friendly way | ||
toast("An error occurred", { | ||
icon: <XCircle weight="fill" className="text-icon-error" />, | ||
}); | ||
console.error(error); | ||
}, | ||
onSuccess: (res) => { | ||
confetti.current(); | ||
toast("Guild successfully created", { | ||
description: "You're being redirected to its page", | ||
icon: <CheckCircle weight="fill" className="text-icon-success" />, | ||
}); | ||
router.push(`/${res.urlName}`); | ||
}, | ||
}); | ||
|
||
return ( | ||
<Button | ||
colorScheme="success" | ||
size="xl" | ||
isLoading={isPending} | ||
loadingText="Creating guild" | ||
onClick={handleSubmit((data) => onSubmit(data))} | ||
> | ||
Create guild | ||
</Button> | ||
); | ||
}; | ||
|
||
export { CreateGuildButton }; |
63 changes: 63 additions & 0 deletions
63
src/app/(dashboard)/create-guild/components/CreateGuildForm.tsx
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 @@ | ||
"use client"; | ||
|
||
import { useFormContext } from "react-hook-form"; | ||
|
||
import { ImageUploader } from "@/components/ImageUploader"; | ||
import { | ||
FormControl, | ||
FormErrorMessage, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
} from "@/components/ui/Form"; | ||
import { Input } from "@/components/ui/Input"; | ||
import type { CreateGuildForm as CreateGuildFormType } from "@/lib/schemas/guild"; | ||
|
||
export const CreateGuildForm = () => { | ||
const { control, setValue } = useFormContext<CreateGuildFormType>(); | ||
|
||
return ( | ||
<> | ||
<div className="mx-auto size-32 rounded-full bg-input-background"> | ||
<ImageUploader | ||
onSuccess={(imageUrl) => | ||
setValue("imageUrl", imageUrl, { | ||
shouldDirty: true, | ||
}) | ||
} | ||
className="size-32" | ||
/> | ||
</div> | ||
|
||
<FormField | ||
control={control} | ||
name="name" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel aria-required>Guild name</FormLabel> | ||
<FormControl> | ||
<Input size="lg" {...field} /> | ||
</FormControl> | ||
|
||
<FormErrorMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
|
||
<FormField | ||
control={control} | ||
name="contact" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel aria-required>E-mail address</FormLabel> | ||
<FormControl> | ||
<Input size="lg" {...field} /> | ||
</FormControl> | ||
|
||
<FormErrorMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
</> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
src/app/(dashboard)/create-guild/components/CreateGuildFormProvider.tsx
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,25 @@ | ||
"use client"; | ||
|
||
import { type CreateGuildForm, CreateGuildSchema } from "@/lib/schemas/guild"; | ||
import { zodResolver } from "@hookform/resolvers/zod"; | ||
import type { PropsWithChildren } from "react"; | ||
import { FormProvider, useForm } from "react-hook-form"; | ||
|
||
const defaultValues = { | ||
name: "", | ||
imageUrl: "", | ||
urlName: "test", | ||
contact: "", | ||
} satisfies CreateGuildForm; | ||
|
||
const CreateGuildFormProvider = ({ children }: PropsWithChildren) => { | ||
const methods = useForm<CreateGuildForm>({ | ||
mode: "onTouched", | ||
resolver: zodResolver(CreateGuildSchema), | ||
defaultValues, | ||
}); | ||
|
||
return <FormProvider {...methods}>{children}</FormProvider>; | ||
}; | ||
|
||
export { CreateGuildFormProvider }; |
Oops, something went wrong.