-
-
Notifications
You must be signed in to change notification settings - Fork 26
Fixed: The add button is not disabled #176
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ 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, | ||
|
@@ -16,8 +17,22 @@ const initialState = { | |
|
||
export default function Form({ usage }) { | ||
const [state, formAction] = useFormState(getRepo, initialState); | ||
const disabled = usage >= process.env.NEXT_PUBLIC_REPO_LIMIT ? true : false; | ||
const [usageLimitReached,setUsageLimitReached] = useState(false) | ||
eddiejaoude marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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_-]+$/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My concern with this, is we should let github return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After more thought, I am concerned that this might present other bugs in the future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I suggested regex so people can't enter non repo links. Like git lab links or spam links, or anything else There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the UX is better, but could create a bug without us knowing. At the moment we rely on github returning a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay so I think we could only check for the domain using regex i.e. whatever the URL is being entered has to be a GitHub URL and let's not check further as if the repo does not exist the GitHub itself will return a 404. Example: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great idea, that is a great idea and comprise 👍 |
||
|
||
useEffect(()=>{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please format files to our project standards |
||
|
||
setUsageLimitReached(usage >= process.env.NEXT_PUBLIC_REPO_LIMIT); | ||
setIsGithubUrlValid(githubRegex.test(githubUrl)) | ||
|
||
setIsDisabled(usageLimitReached || !isGithubUrlValid) | ||
|
||
},[usage,githubUrl]) | ||
|
||
return ( | ||
<form action={formAction}> | ||
<Alert> | ||
|
@@ -30,13 +45,15 @@ export default function Form({ usage }) { | |
</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={state?.data?.url} | ||
disabled={disabled} | ||
value={githubUrl} | ||
onChange={(e)=>setGithubUrl(e.target.value)} | ||
disabled={usageLimitReached} | ||
/> | ||
</div> | ||
</div> | ||
|
@@ -79,7 +96,8 @@ export default function Form({ usage }) { | |
</fieldset> | ||
|
||
<div className="mt-6 flex items-center justify-end gap-x-6"> | ||
<SubmitButton text="SAVE" disabled={disabled} /> | ||
<SubmitButton text="SAVE" disabled={isDisabled} /> | ||
|
||
</div> | ||
</form> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not use
main
in your fork, because these changes should not be in your 2nd PRThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So i should checkout to some other branch and then push the changes.Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should always create a new branch from
main
, but you never push to main, your changes only enter main when your PR is accepted and merged, then you update your main to be in sync with upstreamI have a video demoing and explain on my youtube channel