feat: mandatory invitation code and invitation page
This commit is contained in:
+36
-14
@@ -15,6 +15,20 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
"/invitations/use": {
|
||||
$post: {
|
||||
input: {
|
||||
json: {
|
||||
code: string;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 0;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
"/wallets/transactions/tip": {
|
||||
$post: {
|
||||
@@ -298,7 +312,9 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
|
||||
};
|
||||
output: {
|
||||
code: 0;
|
||||
data: Record<string, number>;
|
||||
data: {
|
||||
[x: string]: number;
|
||||
};
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
@@ -559,21 +575,27 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
|
||||
};
|
||||
};
|
||||
output: {
|
||||
data: Record<string, {
|
||||
description: string;
|
||||
name: string;
|
||||
url: string;
|
||||
routes: Record<string, {
|
||||
path: string;
|
||||
example: string;
|
||||
data: {
|
||||
[x: string]: {
|
||||
description: string;
|
||||
name: string;
|
||||
categories: string[];
|
||||
parameters: Record<string, string>;
|
||||
maintainers: string[];
|
||||
location: string;
|
||||
}>;
|
||||
}>;
|
||||
url: string;
|
||||
routes: {
|
||||
[x: string]: {
|
||||
path: string;
|
||||
example: string;
|
||||
description: string;
|
||||
name: string;
|
||||
categories: string[];
|
||||
parameters: {
|
||||
[x: string]: string;
|
||||
};
|
||||
maintainers: string[];
|
||||
location: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
|
||||
@@ -30,6 +30,14 @@ export const apiFetch = ofetch.create({
|
||||
// Or we can present LoginModal here.
|
||||
router.navigate("/login")
|
||||
}
|
||||
try {
|
||||
const json = JSON.parse(context.response._data)
|
||||
if (context.response.status === 400 && json.code === 1003) {
|
||||
router.navigate("/invitation")
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { Logo } from "@renderer/components/icons/logo"
|
||||
import { StyledButton } from "@renderer/components/ui/button"
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@renderer/components/ui/form"
|
||||
import { Input } from "@renderer/components/ui/input"
|
||||
import { useInvitationMutation } from "@renderer/queries/invitations"
|
||||
import { useEffect } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useNavigate } from "react-router-dom"
|
||||
import { z } from "zod"
|
||||
|
||||
const formSchema = z.object({
|
||||
code: z.string().min(1),
|
||||
})
|
||||
|
||||
export function Component() {
|
||||
const navigate = useNavigate()
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
})
|
||||
const invitationMutation = useInvitationMutation()
|
||||
|
||||
function onSubmit(values: z.infer<typeof formSchema>) {
|
||||
invitationMutation.mutate(values.code)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (invitationMutation.isSuccess) {
|
||||
navigate("/")
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-full flex-col items-center justify-center gap-10 px-10">
|
||||
<Logo className="size-20" />
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(onSubmit)}
|
||||
className="w-[512px] space-y-8"
|
||||
>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="code"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Invitation Code</FormLabel>
|
||||
<FormControl>
|
||||
<Input autoFocus {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="center flex">
|
||||
<StyledButton type="submit" isLoading={invitationMutation.isPending}>
|
||||
Active
|
||||
</StyledButton>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
<div className="text-sm text-zinc-500">
|
||||
😰 Sorry, Follow is currently in
|
||||
{" "}
|
||||
<strong>early access</strong>
|
||||
{" "}
|
||||
and requires an invitation to use.
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { apiClient, getFetchErrorMessage } from "@renderer/lib/api-fetch"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { toast } from "sonner"
|
||||
|
||||
export const useInvitationMutation = () => useMutation({
|
||||
mutationFn: (code: string) => apiClient.invitations.use.$post({ json: { code } }),
|
||||
onSuccess() {},
|
||||
async onError(err) {
|
||||
toast.error(await getFetchErrorMessage(err))
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user