-
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
159376b
commit 4d64545
Showing
26 changed files
with
438 additions
and
151 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {getShareEntry} from "@/lib/db/shares/get-share-entry"; | ||
import {notFound} from "next/navigation"; | ||
import CopyContainer from "@/components/copy-container"; | ||
import {QRCode} from "@/components/qrcode-card"; | ||
|
||
export default async function ShareIdPage({params}: {params: {shareId: string}}) { | ||
const shareEntry = await getShareEntry(params.shareId); | ||
|
||
if (!shareEntry?.beanconquerorUrl) { | ||
return notFound(); | ||
} | ||
|
||
const shareUrl = `https://beanstats.com/s/${shareEntry.publicId}`; | ||
|
||
return ( | ||
<div className={"flex flex-col items-center space-y-6"}> | ||
<section className={"text-center max-w-xl space-y-6"}> | ||
<h1 className={"text-4xl md:text-6xl font-bold text-center"}> | ||
Share a <span className={"gradient-text"}>Beanconqueror</span> link | ||
</h1> | ||
<p className={"text-center"}> | ||
Your share link has been shortened, copy the link or scan the qrcode with your phone camera. | ||
</p> | ||
</section> | ||
<section className={"w-full text-center"}> | ||
<h3 className={"text-2xl font-semibold"}>{shareEntry.name}</h3> | ||
<div className={"italic"}> | ||
Roasted by {shareEntry.roaster} | ||
</div> | ||
</section> | ||
<CopyContainer value={shareUrl} /> | ||
<QRCode value={shareUrl} /> | ||
</div> | ||
); | ||
} |
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,26 @@ | ||
"use server"; | ||
|
||
import {redirect} from "next/navigation"; | ||
import {getShortShareEntry} from "@/lib/share/actions"; | ||
import {shortLinkFormSchema} from "@/components/beanconqueror/share/shorten/schema"; | ||
|
||
export type ShortenLinkFormState = { | ||
error: string | null | ||
} | ||
|
||
export async function processShortenLink(prevState: ShortenLinkFormState, formData: FormData): Promise<ShortenLinkFormState> { | ||
const link = formData.get("link") as string | null; | ||
const parsed = shortLinkFormSchema.shape.link.safeParse(link); | ||
|
||
if (!parsed.success || !link) { | ||
return {error: "invalid or missing link provided"}; | ||
} | ||
|
||
const share = await getShortShareEntry(link); | ||
|
||
if (!share?.publicId) { | ||
return {error: "something went wrong while shortening the link"}; | ||
} | ||
|
||
redirect(`/beanconqueror/shorten/${share.publicId}`); | ||
} |
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,28 +1,28 @@ | ||
import {type Metadata} from "next"; | ||
|
||
import {ShortenContainer} from "@/components/beanconqueror/share/shorten/shorten-link-container"; | ||
import {ShortLinkForm} from "@/components/beanconqueror/share/shorten/form"; | ||
import PageShell from "@/components/layout/page-shell"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Shorten Beanconqueror link", | ||
description: "Shorten a Beanconqueror (share) link using this Beanlink", | ||
openGraph: { | ||
title: "Shorten a (share) link", | ||
description: "Shorten a Beanconqueror (share) link using Beanlink", | ||
images: ["/beanconqueror_logo.png"], | ||
}, | ||
title: "Shorten Beanconqueror link", | ||
description: "Shorten a Beanconqueror (share) link", | ||
openGraph: { | ||
title: "Shorten a (share) link", | ||
description: "Shorten a Beanconqueror (share) link", | ||
images: ["/beanconqueror_logo.png"], | ||
}, | ||
}; | ||
|
||
export default function CreateShareLinkPage() { | ||
return ( | ||
<PageShell> | ||
<h1 className={"text-4xl md:text-6xl font-bold text-center"}> | ||
Shorten a <span className={"gradient-text"}>Beanconqueror</span> share link | ||
</h1> | ||
<p className={"text-center"}> | ||
This form uses Beanlink to shorten a Beanconqueror share link. | ||
</p> | ||
<ShortenContainer link={null} /> | ||
</PageShell> | ||
); | ||
return ( | ||
<PageShell> | ||
<h1 className={"text-4xl md:text-6xl font-bold text-center"}> | ||
Shorten a <span className={"gradient-text"}>Beanconqueror</span> share link | ||
</h1> | ||
<p className={"text-center"}> | ||
This form creates a shorter and easier-to-share Beanconqueror share link. | ||
</p> | ||
<ShortLinkForm /> | ||
</PageShell> | ||
); | ||
} |
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,3 @@ | ||
# s | ||
|
||
s path contains the share links and is short for share |
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,47 @@ | ||
import {type Metadata} from "next"; | ||
import {notFound, redirect} from "next/navigation"; | ||
|
||
import {getShareEntry} from "@/lib/db/shares/get-share-entry"; | ||
|
||
export async function generateMetadata({params}: {params: {shareId: string}}): Promise<Metadata> { | ||
const shareEntry = await getShareEntry(params.shareId); | ||
|
||
if (!shareEntry) { | ||
return { | ||
title: "Beanconqueror import link", | ||
description: "Provided by Beanstats", | ||
openGraph: { | ||
title: "Beanconqueror import link", | ||
description: "Import this coffee into your Beanconqueror app", | ||
images: ["/beanconqueror_logo.png"], | ||
}, | ||
}; | ||
} | ||
|
||
const roaster = !!shareEntry.roaster ? ` roasted by ${shareEntry.roaster ?? "??"}` : ""; | ||
|
||
return { | ||
title: `${shareEntry.name}${roaster}`, | ||
description: "Provided by Beanstats", | ||
openGraph: { | ||
title: "Beanconqueror import link", | ||
description: "Import this coffee into your Beanconqueror app", | ||
images: ["/beanconqueror_logo.png"], | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* Simple redirect page for a shortened share url | ||
* @param params | ||
* @constructor | ||
*/ | ||
export default async function ShareLinkPage({params}: {params: {shareId: string}}) { | ||
const shareEntry = await getShareEntry(params.shareId); | ||
|
||
if (!shareEntry?.beanconquerorUrl) { | ||
return notFound(); | ||
} | ||
|
||
redirect(shareEntry.beanconquerorUrl); | ||
} |
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,82 @@ | ||
"use client"; | ||
|
||
import {useForm} from "react-hook-form"; | ||
import {useFormState, useFormStatus} from "react-dom"; | ||
import {type z} from "zod"; | ||
import {zodResolver} from "@hookform/resolvers/zod"; | ||
|
||
import {processShortenLink} from "@/app/beanconqueror/(share)/shorten/actions"; | ||
import {Form, FormControl, FormField, FormItem, FormLabel, FormMessage} from "@/components/ui/form"; | ||
import {Input} from "@/components/ui/input"; | ||
import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert"; | ||
import {AlertCircle, Loader} from "lucide-react"; | ||
import {useToast} from "@/components/ui/use-toast"; | ||
import {Button} from "@/components/ui/button"; | ||
import {shortLinkFormSchema} from "@/components/beanconqueror/share/shorten/schema"; | ||
|
||
function SubmitButton() { | ||
const {pending} = useFormStatus(); | ||
return ( | ||
<Button type={"submit"} aria-disabled={pending} disabled={pending}> | ||
{pending ? "Shortening" : "Shorten"} | ||
{pending && <Loader className={"animate-spin h-4 w-4 ml-2"} />} | ||
</Button> | ||
) | ||
} | ||
|
||
export function ShortLinkForm() { | ||
const form = useForm<z.infer<typeof shortLinkFormSchema>>({ | ||
resolver: zodResolver(shortLinkFormSchema), | ||
defaultValues: { | ||
link: "", | ||
} | ||
}); | ||
const [state, action] = useFormState(processShortenLink, {error: null}); | ||
const {toast} = useToast(); | ||
|
||
const validateData = (formData: FormData) => { | ||
const parseResult = shortLinkFormSchema.shape.link.safeParse(formData.get("link")); | ||
|
||
if (!parseResult.success) { | ||
toast({ | ||
title: "Invalid url", | ||
description: "Did not receive a valid Beanconqueror url", | ||
variant: "destructive", | ||
}); | ||
return; | ||
} | ||
action(formData); | ||
}; | ||
|
||
return ( | ||
<Form {...form}> | ||
<form action={validateData}> | ||
<fieldset className={"flex items-end gap-2"}> | ||
<FormField<z.infer<typeof shortLinkFormSchema>> | ||
name={"link"} | ||
control={form.control} | ||
render={({field}) => ( | ||
<FormItem> | ||
<FormLabel>Link</FormLabel> | ||
<FormControl> | ||
<Input placeholder={"Enter here"} {...field} /> | ||
</FormControl> | ||
<FormMessage/> | ||
</FormItem> | ||
)} | ||
/> | ||
<SubmitButton /> | ||
</fieldset> | ||
{!!state.error && ( | ||
<Alert variant={"destructive"}> | ||
<AlertCircle className={"h-4 w-4"}/> | ||
<AlertTitle>Error</AlertTitle> | ||
<AlertDescription> | ||
{state.error} | ||
</AlertDescription> | ||
</Alert> | ||
)} | ||
</form> | ||
</Form> | ||
); | ||
} |
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,8 @@ | ||
import {z} from "zod"; | ||
import {BEANCONQUEROR_RE} from "@/lib/beanconqueror/validations/links"; | ||
|
||
export const shortLinkFormSchema = z.object( | ||
{ | ||
link: z.string().url().regex(BEANCONQUEROR_RE, {message: "Provide a valid Beanconqueror url"}) | ||
} | ||
); |
24 changes: 0 additions & 24 deletions
24
src/components/beanconqueror/share/shorten/shorten-link-container.tsx
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
Oops, something went wrong.