TicketEditForm.js 5.47 KB
Newer Older
1
2
3
4
5
6
import { useState, useEffect } from "react";
import cinemaApi from "../../apis/cinema.api.js";
import catchErrors from "../../utils/catchErrors.js";
import styles from "./admin.module.scss";

const INIT_TICKETFEE = {
7
8
    theatertypeId: 0,
    theaterTypeName: "",
Kim, Subin's avatar
Kim, Subin committed
9
10
11
12
13
14
15
16
    weekdays: "",
    weekend: "",
    morning: "",
    day: "",
    night: "",
    youth: "",
    adult: "",
    senior: "",
17
18
19
    defaultPrice: 5000
}

Kim, Subin's avatar
Kim, Subin committed
20
const TicketEditForm = ({ editFee, formRef }) => {
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    const [ticketFee, setTicketFee] = useState(INIT_TICKETFEE)
    const [error, setError] = useState("")

    useEffect(() => {
        setTicketFee({ ...ticketFee, ...editFee })
    }, [editFee])

    function handleChange(e) {
        const { name, value } = e.target
        setTicketFee({ ...ticketFee, [name]: value })
    }

    async function handleSubmit(e) {
        e.preventDefault()
        try {
            setError("")
            await cinemaApi.editTicketFee(ticketFee)
            alert("해당 관람료 정보 등록이 성공적으로 완료되었습니다.")
            window.location.reload()
        } catch (error) {
            catchErrors(error, setError)
        }
    }

    return (
Kim, Subin's avatar
Kim, Subin committed
46
        <form ref={formRef} onSubmit={handleSubmit}>
47
            {console.log("fidsapd===",editFee)}
Kim, Subin's avatar
Kim, Subin committed
48
            <div className="d-flex row row-cols-2 mb-2 mb-md-3 gx-0 gy-2 gy-md-0">
Kim, Subin's avatar
theater    
Kim, Subin committed
49
                <label htmlfor="theaterType" className="col-md-auto col-form-label text-center text-md-start">상영관 종류</label>
Kim, Subin's avatar
Kim, Subin committed
50
                <div className="col-md-4 col-lg-3 mx-md-2">
51
                    <input className={`form-control ${styles.shadowNone}`} type="text" id="theaterTypeName" name="theaterTypeName" value={ticketFee.theaterTypeName} onChange={handleChange} />
52
                </div>
Kim, Subin's avatar
theater    
Kim, Subin committed
53
                <label htmlfor="defaultPrice" className="col-md-auto col-form-label text-center text-md-start">기본 가격</label>
Kim, Subin's avatar
Kim, Subin committed
54
                <div className="col-md-3 col-lg-2 mx-md-2">
55
56
57
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="defaultPrice" name="defaultPrice" value={ticketFee.defaultPrice} onChange={handleChange} />
                </div>
            </div>
Kim, Subin's avatar
Kim, Subin committed
58
            <div className="d-flex row row-cols-2 mb-2 mb-md-3 gx-0 gy-2 gy-md-0">
Kim, Subin's avatar
theater    
Kim, Subin committed
59
                <label htmlfor="weekdays" className="col-md-1 col-form-label text-center text-md-start">주중</label>
Kim, Subin's avatar
Kim, Subin committed
60
                <div className="col-md-3 col-lg-2">
61
62
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="weekdays" name="weekdays" value={ticketFee.weekdays} onChange={handleChange} />
                </div>
Kim, Subin's avatar
theater    
Kim, Subin committed
63
                <label htmlfor="weekend" className="col-md-1 col-form-label text-center">주말</label>
Kim, Subin's avatar
Kim, Subin committed
64
                <div className="col-md-3 col-lg-2">
65
66
67
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="weekend" name="weekend" value={ticketFee.weekend} onChange={handleChange} />
                </div>
            </div>
Kim, Subin's avatar
Kim, Subin committed
68
            <div className="d-flex row row-cols-2 mb-2 mb-md-3 gx-0 gy-2 gy-md-0">
Kim, Subin's avatar
theater    
Kim, Subin committed
69
                <label htmlfor="morning" className="col-md-1 col-form-label text-center text-md-start">조조</label>
Kim, Subin's avatar
Kim, Subin committed
70
                <div className="col-md-3 col-lg-2">
71
72
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="morning" name="morning" value={ticketFee.morning} onChange={handleChange} />
                </div>
Kim, Subin's avatar
theater    
Kim, Subin committed
73
                <label htmlfor="day" className="col-md-1 col-form-label text-center">일반</label>
Kim, Subin's avatar
Kim, Subin committed
74
                <div className="col-md-3 col-lg-2">
75
76
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="day" name="day" value={ticketFee.day} onChange={handleChange} />
                </div>
Kim, Subin's avatar
theater    
Kim, Subin committed
77
                <label htmlfor="night" className="col-md-1 col-form-label text-center">심야</label>
Kim, Subin's avatar
Kim, Subin committed
78
                <div className="col-md-3 col-lg-2">
79
80
81
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="night" name="night" value={ticketFee.night} onChange={handleChange} />
                </div>
            </div>
Kim, Subin's avatar
Kim, Subin committed
82
            <div className="d-flex row row-cols-2 flex-wrap flex-lg-nowrap mb-2 mb-md-3 gx-0 gy-2 gy-md-0">
Kim, Subin's avatar
theater    
Kim, Subin committed
83
                <label htmlfor="youth" className="col-md-1 col-form-label text-center text-md-start">청소년</label>
Kim, Subin's avatar
Kim, Subin committed
84
                <div className="col-md-3 col-lg-2">
85
86
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="youth" name="youth" value={ticketFee.youth} onChange={handleChange} />
                </div>
Kim, Subin's avatar
theater    
Kim, Subin committed
87
                <label htmlfor="adult" className="col-md-1 col-form-label text-center">일반</label>
Kim, Subin's avatar
Kim, Subin committed
88
                <div className="col-md-3 col-lg-2">
89
90
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="adult" name="adult" value={ticketFee.adult} onChange={handleChange} />
                </div>
Kim, Subin's avatar
theater    
Kim, Subin committed
91
                <label htmlfor="senior" className="col-md-1 col-form-label text-center">경로</label>
Kim, Subin's avatar
Kim, Subin committed
92
                <div className="col-md-3 col-lg-2">
93
94
                    <input className={`form-control ${styles.shadowNone}`} type="number" id="senior" name="senior" value={ticketFee.senior} onChange={handleChange} />
                </div>
Kim, Subin's avatar
Kim, Subin committed
95
96
                <div className="col-12 col-md-2 col-lg-1 ms-lg-auto mt-md-2 mt-lg-0">
                    <button type="submit" className={`btn btn-dark w-100 ${styles.customBtn}`}>추가</button>
97
98
99
100
101
102
103
                </div>
            </div>
        </form>
    )
}

export default TicketEditForm