MCPcopy Create free account
hub / github.com/TheOrcDev/github-creature / SubmitGithubForm

Function SubmitGithubForm

components/forms/github-form.tsx:52–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50 const segments = url.pathname.split("/").filter(Boolean);
51 if (segments.length !== 1) {
52 return false;
53 }
54 const username = decodeURIComponent(segments[0] ?? "").trim();
55 return usernameRegex.test(username);
56 } catch {
57 return false;
58 }
59 }
60
61 // Otherwise validate as a username
62 return usernameRegex.test(trimmed);
63 }, "Please enter a valid GitHub username or profile URL"),
64});
65
66export function GithubFormFallback() {
67 return (
68 <div className="flex w-full max-w-md flex-col items-center gap-5">
69 <Skeleton className="h-8 w-3/4" />
70 <Skeleton className="h-8 w-full" />
71 </div>
72 );
73}
74
75export function SubmitGithubForm() {
76 const router = useRouter();
77 const [loading, setLoading] = React.useState(false);
78 const username = useInitialUsername();
79
80 const form = useForm<z.infer<typeof formSchema>>({
81 defaultValues: {
82 githubProfileUrl: username ? `https://github.com/${username}` : "",
83 },
84 resolver: zodResolver(formSchema),
85 });
86
87 async function onSubmit(data: z.infer<typeof formSchema>) {
88 try {
89 setLoading(true);
90 const result = await submitGithubForm(data.githubProfileUrl);
91
92 if (result && result.success) {
93 toast.success(result.message);
94 if (result.redirectUrl) {
95 router.push(result.redirectUrl);
96 }
97 } else if (result && !result.success) {
98 toast.error(result.message);
99 }
100 } finally {
101 setLoading(false);
102 }
103 }
104
105 return (
106 <>
107 {loading ? (
108 <div className="flex items-center gap-2">
109 <h2 className="text-center font-bold text-2xl md:text-xl lg:text-4xl">

Callers

nothing calls this directly

Calls 1

useInitialUsernameFunction · 0.90

Tested by

no test coverage detected