This repository was archived by the owner on Oct 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathform.js
More file actions
104 lines (88 loc) · 3.11 KB
/
form.js
File metadata and controls
104 lines (88 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"use client";
import { useFormState } from "react-dom";
import { getRepo } from "./action";
import { SubmitButton } from "@/components/forms/SubmitButton";
import Input from "@/components/forms/Input";
import Checkbox from "@/components/forms/Checkbox";
import Alert from "@/components/Alert";
import {useState,useEffect} from "react"
const initialState = {
data: undefined,
success: undefined,
errors: undefined,
};
export default function Form({ usage }) {
const [state, formAction] = useFormState(getRepo, initialState);
const [usageLimitReached,setUsageLimitReached] = useState(false)
const [githubUrl , setGithubUrl] = useState(state?.data?.url || '')
const [isGithubUrlValid,setIsGithubUrlValid] = useState(false)
const [isDisabled,setIsDisabled] = useState(true)
const githubRegex = /^https:\/\/github\.com\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
useEffect(()=>{
setUsageLimitReached(usage >= process.env.NEXT_PUBLIC_REPO_LIMIT);
setIsGithubUrlValid(githubRegex.test(githubUrl))
setIsDisabled(usageLimitReached || !isGithubUrlValid)
},[usage,githubUrl])
return (
<form action={formAction}>
<Alert>
You have ({usage}/{process.env.NEXT_PUBLIC_REPO_LIMIT}) repos remaining
</Alert>
<div className="space-y-12">
<div className="border-b border-gray-900/10 pb-12">
<p className="mt-1 text-sm leading-6 text-gray-300">
This will load the GitHub repo information from the GitHub API
</p>
<div className="mt-10 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
<Input
id="url"
name="url"
text="GitHub repo URL"
error={state?.errors?.url}
value={githubUrl}
onChange={(e)=>setGithubUrl(e.target.value)}
disabled={usageLimitReached}
/>
</div>
</div>
</div>
<fieldset>
<legend className="text-sm font-semibold leading-6">Visibility</legend>
<div className="mt-6 space-y-6">
<Checkbox
id="isPrivate"
name="isPrivate"
text="Private"
value={true}
description="Do NOT display your GitHub repo on the homepage"
disabled={true}
/>
</div>
</fieldset>
<fieldset className="mt-12">
<legend className="text-sm font-semibold leading-6">
Notifications
</legend>
<div className="mt-6 space-y-6">
<Checkbox
id="trending"
name="trending"
text="Trending"
description="Get notified when you are trending on GitHub"
disabled={true}
/>
<Checkbox
id="change"
name="change"
text="Status change"
description="Get notified when a status degrades and goes down a level"
disabled={true}
/>
</div>
</fieldset>
<div className="mt-6 flex items-center justify-end gap-x-6">
<SubmitButton text="SAVE" disabled={isDisabled} />
</div>
</form>
);
}