|
| 1 | +import { useEventState } from '@/stores/myEventsStore.ts'; |
| 2 | +import DialogButton from '@/components/common/DialogButton'; |
| 3 | +import { InputRef } from '../common/InputForm.tsx'; |
| 4 | +import { useState, useRef } from 'react'; |
| 5 | + |
| 6 | +const CreateEventButton = () => { |
| 7 | + const { addEvents } = useEventState(); |
| 8 | + const [eventTitle, setTitle] = useState(''); |
| 9 | + const [startDate, setStartDate] = useState(''); |
| 10 | + const [endDate, setEndDate] = useState(''); |
| 11 | + const titleRef = useRef<HTMLInputElement>(null); |
| 12 | + const startRef = useRef<HTMLInputElement>(null); |
| 13 | + const endRef = useRef<HTMLInputElement>(null); |
| 14 | + |
| 15 | + const onTitleChanged = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 16 | + setTitle(event.target.value); |
| 17 | + }; |
| 18 | + |
| 19 | + const onStartDateChanged = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 20 | + setStartDate(event.target.value); |
| 21 | + }; |
| 22 | + |
| 23 | + const onEndDateChanged = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 24 | + setEndDate(event.target.value); |
| 25 | + }; |
| 26 | + |
| 27 | + const onCreateClicked = () => { |
| 28 | + if (eventTitle !== '' && startDate !== '') { |
| 29 | + addEvents({ title: eventTitle, start: startDate, end: endDate === '' ? startDate : endDate }); |
| 30 | + } |
| 31 | + setTitle(''); |
| 32 | + setStartDate(''); |
| 33 | + setEndDate(''); |
| 34 | + if (titleRef.current) { |
| 35 | + titleRef.current.value = ''; |
| 36 | + } |
| 37 | + if (startRef.current) { |
| 38 | + startRef.current.value = ''; |
| 39 | + } |
| 40 | + if (endRef.current) { |
| 41 | + endRef.current.value = ''; |
| 42 | + } |
| 43 | + }; |
| 44 | + |
| 45 | + const eventForm = ( |
| 46 | + <div> |
| 47 | + <hr className="mt-1" /> |
| 48 | + <InputRef title="์ผ์ ์ ๋ชฉ" placeholder="์ ์ผ์ ์ ๋ชฉ" onChange={onTitleChanged} ref={titleRef} /> |
| 49 | + <InputRef title="์์ ๋ ์ง" placeholder="YYYY-MM-DD" onChange={onStartDateChanged} ref={startRef} /> |
| 50 | + <InputRef title="๋ ๋ ์ง" placeholder="YYYY-MM-DD" onChange={onEndDateChanged} ref={endRef} /> |
| 51 | + <hr className="mb-2 mt-2" /> |
| 52 | + <button className="btn w-full bg-primary text-base-100" onClick={onCreateClicked}> |
| 53 | + ์ถ๊ฐํ๊ธฐ |
| 54 | + </button> |
| 55 | + </div> |
| 56 | + ); |
| 57 | + return ( |
| 58 | + <div className="p-8"> |
| 59 | + <DialogButton |
| 60 | + classname="btn bg-primary text-base-100 w-full" |
| 61 | + name={'์ ์ผ์ ์ถ๊ฐํ๊ธฐ'} |
| 62 | + title={'์ผ์ ์ถ๊ฐ'} |
| 63 | + desc={''} |
| 64 | + children={eventForm} |
| 65 | + /> |
| 66 | + </div> |
| 67 | + ); |
| 68 | +}; |
| 69 | +export default CreateEventButton; |
0 commit comments