Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jin-co committed May 8, 2024
1 parent 483a44e commit 966922c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
19 changes: 16 additions & 3 deletions React/test-feedback/package-lock.json

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

1 change: 1 addition & 0 deletions React/test-feedback/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"react-router": "^6.23.0",
"react-router-dom": "^6.23.0",
"react-scripts": "5.0.1",
"uuid": "^9.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
30 changes: 25 additions & 5 deletions React/test-feedback/src/components/feed/FeedForm.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
import React from 'react'
import React, { useState } from 'react'
import { FeedRating } from './FeedRating'
import { Button } from '../shared/Button'
import { Card } from '../shared/Card'
import { v4 as uuid } from 'uuid'

export const FeedForm = (props) => {
const [text, setText] = useState('')
const [rating, setRating] = useState(0)
const [isDisabled, setIsDisabled] = useState(true)

const handleSubmit = (e) => {
console.log('ss')
e.preventDefault()
const newFeed = {
id: uuid(),
text,
rating
}
props.addFeed(newFeed)
}

const handleChange = (e) => {
setText(e.target.value)
if (e.target.value.length > 10) {
setIsDisabled(false)
} else {
setIsDisabled(true)
}
}

return (
<Card>
<form onSubmit={handleSubmit} >
<h2>How would you rate your service with us?</h2>
<FeedRating />
<FeedRating onChange={(e) => setRating(e.rating)} />
<div className="input-group">
<input

onChange={handleChange}
type="text"

value={text}
placeholder="Write a review"
/>
<Button type={'submit'} >
<Button type={'submit'} isDisabled={isDisabled} >
Send
</Button>
</div>
Expand Down
5 changes: 4 additions & 1 deletion React/test-feedback/src/components/shared/Button.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react'
import React, { useEffect } from 'react'

export const Button = (props, { version = 'secondary', type = 'button' }) => {
useEffect(() => {
console.log(version, type)
}, [])
return (
<button type={type} disabled={props.isDisabled} className={`btn btn-${version}`}>
{props.children}
Expand Down
1 change: 1 addition & 0 deletions React/test-feedback/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const Home = () => {
}

const addFeed = (feed) => {
console.log(feed)
setFeed(feed.push(feed))
}

Expand Down

0 comments on commit 966922c

Please sign in to comment.