Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
fix: able to add the same repo twice (#975)
Browse files Browse the repository at this point in the history
* feat(repository-goals): pass goals to addRepoForm

* fix(add-repo-form): add check for duplicate repo
  • Loading branch information
farisaziz12 committed May 2, 2021
1 parent 5c7048c commit d10d3a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/components/AddRepoForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {isValidRepoUrl} from "../lib/util";
import {repoStatusCode} from "../lib/repoStatusCode";
import {ErrorMessage} from "../styles/Typography";

function AddRepoForm({goalsId, onGoalAdded}) {
function AddRepoForm({goalsId, onGoalAdded, goals}) {
const urlRef = useRef(null);
const [error, setError] = useState(null);

Expand All @@ -22,13 +22,20 @@ function AddRepoForm({goalsId, onGoalAdded}) {

const [isValid, repoUrl] = isValidRepoUrl(urlRef.current.value.replace(/\s+/g, ""));
const statusCode = await repoStatusCode(repoUrl);
const goalExists = goals.nodes.find(goal => goal.full_name === repoUrl);

if (!isValid) {
urlRef.current.focus();
setError("Invalid GitHub repository!");
return;
}

if (goalExists) {
urlRef.current.focus();
setError("Already exists!");
return;
}

if (statusCode === 404) {
urlRef.current.focus();
setError("Repository not found!");
Expand Down
2 changes: 1 addition & 1 deletion src/components/RepositoryGoals.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function RepositoryGoals({user}) {
</SpaceBetweenTop>
</ContextStyle>
<Cards fitted>
<AddRepoForm goalsId={goalsId} onGoalAdded={onGoalAdded} />
<AddRepoForm goalsId={goalsId} onGoalAdded={onGoalAdded} goals={repository.issues} />
{repository.issues.totalCount > 0 ? (
<ListGoals data={data} goals={repository.issues} />
) : (
Expand Down

0 comments on commit d10d3a2

Please sign in to comment.