Skip to content

Commit

Permalink
FIX: prevent sending one word question (#67)
Browse files Browse the repository at this point in the history
Closes #54 

## Description

- Added validation using Valibot to ensure that a space character is included in the question
- Ran pnpm run format then pnpm run lint --fix to auto format the code
- Tested the validation from local
- Resolved merge conflict

## Testing

- [ Test new validation on local - test one word question produces correct error message ] (test 1)
![image](https://github.com/mazipan/tanyaaja/assets/98062538/6aeba565-b5d1-4a3b-a354-1773c5e06a56)
- [ Test new validation on local - test two word question goes through and appears in DB ] (test 2)
![test2-1](https://github.com/mazipan/tanyaaja/assets/98062538/159fd179-0fee-47c8-a98e-90e1f2518699)
![test2-2](https://github.com/mazipan/tanyaaja/assets/98062538/48170796-6882-4b6d-9f35-9c28f5cfb043)
- [ Test existing validation on local - test blank question produces error ] (test 3)
![test3](https://github.com/mazipan/tanyaaja/assets/98062538/deb6f02e-d8ea-42c0-9942-d9169d415d19)
  • Loading branch information
kodiakhq[bot] committed Oct 13, 2023
2 parents a3c4cee + 17737ed commit b14e80a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/modules/PublicQuestionPage/QuestionForm.tsx
Expand Up @@ -6,7 +6,14 @@ import Script from 'next/script'

import { valibotResolver } from '@hookform/resolvers/valibot'
import { Loader2, Lock, SendHorizontal } from 'lucide-react'
import { maxLength, minLength, object, type Output, string } from 'valibot'
import {
includes,
maxLength,
minLength,
object,
type Output,
string,
} from 'valibot'

// @ts-ignore
import { ShareButton } from '@/components/ShareButton'
Expand All @@ -30,6 +37,7 @@ const schema = object({
q: string('Pertanyaan perlu disi terlebih dahulu.', [
minLength(2, 'Pertanyaan butuh paling tidak 2 karakter.'),
maxLength(500, 'Pertanyaan hanya bisa maksimal 1000 karakter.'),
includes(' ', 'Pertanyaan membutuhkan lebih dari satu kata.'),
]),
})

Expand Down

0 comments on commit b14e80a

Please sign in to comment.