Skip to content

Commit

Permalink
fix: disable create page button only if insight page name is empty (#893
Browse files Browse the repository at this point in the history
)

Fixes #892
  • Loading branch information
takanome-dev committed Feb 21, 2023
1 parent ba9e7a5 commit ed52399
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions components/organisms/InsightPage/InsightPage.tsx
Expand Up @@ -69,15 +69,23 @@ const InsightPage = ({ edit, insight, pageRepos }: InsightPageProps) => {
};
});

const handleOnNameChange = (value: string) => {
const validateName = (name: string) => {
if (!name || name.trim().length <= 3) return false;

return true;
};

const handleOnNameChange = (value: string) => {
setName(value);
setIsNameValid(validateName(value));
};

if (!value || value.trim().length <= 3) setIsNameValid(false);
const disableCreateButton = () => {
if (insight?.name && validateName(name)) return false;
if (submitted) return true;
if (!isNameValid) return true;

if (value.trim().length > 3) {
setIsNameValid(true);
}
return false;
};

const handleCreateInsightPage = async () => {
Expand Down Expand Up @@ -279,7 +287,7 @@ const InsightPage = ({ edit, insight, pageRepos }: InsightPageProps) => {
handleUpdatePage={handleUpdateInsightPage}
handleAddToCart={handleReAddRepository}
history={reposRemoved}
createPageButtonDisabled={submitted || !isNameValid}
createPageButtonDisabled={disableCreateButton()}
>
{repos.map((repo) => {
const totalPrs =
Expand Down

0 comments on commit ed52399

Please sign in to comment.