Skip to content

Commit

Permalink
fix(1591,1604,1606): fixed qa reported bugs
Browse files Browse the repository at this point in the history
- Space characters as valid input
- Archived ideas having edit
- Unvoting text loader
  • Loading branch information
akhilmhdh committed Nov 10, 2021
1 parent 800881a commit 5df6c7a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idea-hub",
"version": "0.1.2",
"version": "0.1.3",
"private": true,
"homepage": "/ideas",
"author": {
Expand All @@ -10,11 +10,11 @@
},
"dependencies": {
"@hookform/resolvers": "^2.6.0",
"@one-platform/opc-base": "^1.0.2-beta",
"@one-platform/opc-base": "^1.0.5-beta",
"@one-platform/opc-feedback": "0.0.9-prerelease",
"@one-platform/opc-menu-drawer": "^0.1.1-prerelease",
"@one-platform/opc-menu-drawer": "^0.1.2-prerelease",
"@one-platform/opc-nav": "0.0.2-prerelease",
"@one-platform/opc-notification-drawer": "^0.1.1-prerelease",
"@one-platform/opc-notification-drawer": "^0.1.2-prerelease",
"@patternfly/react-core": "^4.128.2",
"@patternfly/react-icons": "^4.10.11",
"@patternfly/react-styles": "^4.10.11",
Expand Down
2 changes: 1 addition & 1 deletion src/components/VoteCard/VoteCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const VoteCard: FC<Props> & CompoundComponents = ({
className="pf-u-py-sm"
style={{ '--pf-c-button--after--BorderRadius': '8px' } as CSSProperties}
>
{isVoting ? 'VOTING' : hasVoted ? 'VOTED' : 'VOTE'}
{hasVoted ? 'VOTED' : 'VOTE'}
</Button>
</FlexItem>
<FlexItem spacer={{ default: 'spacerXs' }}>
Expand Down
8 changes: 7 additions & 1 deletion src/containers/CommentsContainer/CommentsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
Button,
Spinner,
} from '@patternfly/react-core';
import * as yup from 'yup';
import { yupResolver } from '@hookform/resolvers/yup';
import { SortAmountDownIcon, CubesIcon } from '@patternfly/react-icons';
import { Controller, useForm } from 'react-hook-form';
import { CommentBox } from './components/CommentBox';
Expand All @@ -41,6 +43,10 @@ interface Props {
ideaDetails: PouchDB.Core.ExistingDocument<IdeaDoc & PouchDB.Core.AllDocsMeta>;
}

const CommentFormValidtor = yup.object({
comment: yup.string().max(1000).trim().required(),
});

const COMMENTS_ON_EACH_LOAD = 20;

export const CommentsContainer = ({ ideaDetails }: Props): JSX.Element => {
Expand All @@ -53,7 +59,7 @@ export const CommentsContainer = ({ ideaDetails }: Props): JSX.Element => {
watch,
setValue,
formState: { isSubmitting },
} = useForm<FormData>();
} = useForm<FormData>({ resolver: yupResolver(CommentFormValidtor) });

const { comments, commentsRef, isCommentsLoading, mutateComments } = useGetComments({
ideaId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import {
Form,
} from '@patternfly/react-core';
import { Controller, useForm } from 'react-hook-form';
import * as yup from 'yup';
import { yupResolver } from '@hookform/resolvers/yup';
import useSWR from 'swr';

import { useFormSelect } from 'hooks';
import { tagDoc } from 'pouchDB';
import { CreateNewIdea } from 'pages/HomePage/types';
import { CreateIdeaDoc, IdeaDoc } from 'pouchDB/types';
import useSWR from 'swr';
import { reqErrorMsg } from 'utils/errorMessages';

interface Props {
handleModalClose: () => void;
Expand All @@ -31,6 +34,16 @@ interface Props {
updateDefaultValue?: IdeaDoc;
}

const IdeaFormValidator = yup.object({
title: yup.string().trim().max(250).required(reqErrorMsg('Title')),
description: yup.string().trim().max(500).required(reqErrorMsg('Description')),
tags: yup.array(
yup.object({
name: yup.string().trim().required(reqErrorMsg('Tag Name')),
})
),
});

export const IdeaCreateUpdateContainer = ({
handleModalClose,
handleCreateOrUpdateIdeaDoc,
Expand All @@ -51,7 +64,7 @@ export const IdeaCreateUpdateContainer = ({
control,
reset,
formState: { isSubmitting },
} = useForm<CreateNewIdea>();
} = useForm<CreateNewIdea>({ resolver: yupResolver(IdeaFormValidator) });

const isUpdate = Boolean(updateDefaultValue?._rev);
const isLoading = !error && !tags;
Expand Down Expand Up @@ -94,9 +107,7 @@ export const IdeaCreateUpdateContainer = ({
fieldId="title"
isRequired
label="Give a title for your idea:"
helperTextInvalid={
error?.type === 'maxLength' && 'Should be less than 250 characters'
}
helperTextInvalid={error?.message}
validated={error ? 'error' : 'default'}
>
<TextInput
Expand All @@ -122,9 +133,7 @@ export const IdeaCreateUpdateContainer = ({
fieldId="desc"
isRequired
label=" Brief description"
helperTextInvalid={
error?.type === 'maxLength' && 'Should be less than 500 characters'
}
helperTextInvalid={error?.message}
validated={error ? 'error' : 'default'}
>
<TextArea
Expand Down Expand Up @@ -176,13 +185,7 @@ export const IdeaCreateUpdateContainer = ({
</Button>
</SplitItem>
<SplitItem>
<Button
key="submit"
variant="primary"
type="submit"
isLoading={isSubmitting}
isDisabled={isSubmitting}
>
<Button key="submit" variant="primary" type="submit" isDisabled={isSubmitting}>
{isUpdate ? 'Update my idea!' : 'Post my idea!'}
</Button>
</SplitItem>
Expand Down
16 changes: 9 additions & 7 deletions src/pages/HomePage/components/IdeaItem/IdeaItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useState, MouseEventHandler } from 'react';
import { useMemo, useState, MouseEventHandler, Fragment } from 'react';

import {
Card,
Expand Down Expand Up @@ -64,9 +64,13 @@ export const IdeaItem = ({
};

const dropdownItems = [
<DropdownItem key="link" component="button" onClick={onEditIdeaClick}>
Edit my idea
</DropdownItem>,
isArchived ? (
<Fragment key="link" />
) : (
<DropdownItem key="link" component="button" onClick={onEditIdeaClick}>
Edit my idea
</DropdownItem>
),
<DropdownItem
key="action"
component="button"
Expand Down Expand Up @@ -101,9 +105,7 @@ export const IdeaItem = ({
isDisabled={isVoting}
isLoading={isVoting}
>
<Text component={TextVariants.small}>
{isVoting ? 'VOTING' : hasVoted ? 'VOTED' : 'VOTE'}
</Text>
<Text component={TextVariants.small}>{hasVoted ? 'VOTED' : 'VOTE'}</Text>
</Button>
</FlexItem>
</Flex>
Expand Down
1 change: 1 addition & 0 deletions src/utils/errorMessages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const reqErrorMsg = (field: string): string => `${field} is a required field`;

0 comments on commit 5df6c7a

Please sign in to comment.