Skip to content

Commit

Permalink
GH-54 fix(form): always render rating form, even if there isn't a doc…
Browse files Browse the repository at this point in the history
…umentID yet
  • Loading branch information
ciampo committed Jul 6, 2020
1 parent 9152bda commit 6f13055
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions components/blog-post/Recipe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function encode(data: { [key: string]: string }): string {
.join('&');
}

const ReviewForm: React.FC<{ documentId: string }> = ({ documentId }) => {
const ReviewForm: React.FC<{ documentId: string | null }> = ({ documentId }) => {
const formRef = useRef<HTMLFormElement>(null);

const handleSubmit = useCallback((e?: React.FormEvent<HTMLFormElement>): void => {
Expand Down Expand Up @@ -136,13 +136,19 @@ const ReviewForm: React.FC<{ documentId: string }> = ({ documentId }) => {
</label>
</p>

<input type="hidden" name={FIELD_NAMES.DOCUMENT_ID} value={documentId} />
<input type="hidden" name={FIELD_NAMES.DOCUMENT_ID} value={documentId || ''} />

{/* Stars */}
{[1, 2, 3, 4, 5].map((i) => (
<label key={`rating-${i}`}>
{i}
<input onChange={handleRadioChange} name={FIELD_NAMES.RATING} type="radio" value={i} />
<input
onChange={handleRadioChange}
name={FIELD_NAMES.RATING}
type="radio"
value={i}
disabled={!documentId}
/>
</label>
))}
</form>
Expand Down Expand Up @@ -185,12 +191,8 @@ const Recipe: React.FC<RecipeProps> = ({ recipe, className }) => {
<br />
Current number of reviews: {reviewsState.data.reviewCount}
<br />
{reviewsState.data.documentId && (
<>
<ReviewForm documentId={reviewsState.data.documentId} />
<noscript>Please enable JavaScript to submit a review for this recipe.</noscript>
</>
)}
<ReviewForm documentId={reviewsState.data.documentId} />
<noscript>Please enable JavaScript to submit a review for this recipe.</noscript>
</p>
</header>

Expand Down

0 comments on commit 6f13055

Please sign in to comment.