CinemaEdit.js 3.86 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import { useState, useEffect } from "react";
2
3
import TicketEditForm from "./TicketEditForm.js";
import TicketFeeTable from "./TicketFeeTable.js";
Kim, Subin's avatar
Kim, Subin committed
4
5
import cinemaApi from "../../apis/cinema.api.js";
import catchErrors from "../../utils/catchErrors.js";
Kim, Subin's avatar
Kim, Subin committed
6
7
import styles from "./admin.module.scss";

Kim, Subin's avatar
Kim, Subin committed
8
const INIT_CINEMAINFO = {
9
10
11
12
13
    cinemaName: "",
    transportation: "",
    parking: "",
    address: "",
    moreFeeInfo: ""
Kim, Subin's avatar
Kim, Subin committed
14
15
}

Kim, Subin's avatar
Kim, Subin committed
16
const CinemaEdit = () => {
Kim, Subin's avatar
Kim, Subin committed
17
    const [cinemaInfo, setCinemaInfo] = useState(INIT_CINEMAINFO)
18
    const [ticketFee, setTicketFee] = useState({})
Kim, Subin's avatar
Kim, Subin committed
19
20
21
22
23
    const [error, setError] = useState("")

    useEffect(() => {
        getInfo()
    }, [])
Kim, Subin's avatar
Kim, Subin committed
24

Kim, Subin's avatar
Kim, Subin committed
25
26
    function handleChange(e) {
        const { name, value } = e.target
Kim, Subin's avatar
Kim, Subin committed
27
        setCinemaInfo({ ...cinemaInfo, [name]: value })
Kim, Subin's avatar
Kim, Subin committed
28
29
    }

Kim, Subin's avatar
Kim, Subin committed
30
31
32
    async function getInfo() {
        try {
            setError("")
33
            const info = await cinemaApi.getCinemaInfo()
Kim, Subin's avatar
Kim, Subin committed
34
35
36
37
38
39
40
41
42
43
            if (info) setCinemaInfo(info)
            else setCinemaInfo(INIT_CINEMAINFO)
        } catch (error) {
            catchErrors(error, setError)
        }
    }

    async function handleSubmit() {
        try {
            setError("")
44
            await cinemaApi.editCinema(cinemaInfo)
Kim, Subin's avatar
Kim, Subin committed
45
46
47
48
49
50
            window.location.reload()
        } catch (error) {
            catchErrors(error, setError)
        }
    }

Kim, Subin's avatar
Kim, Subin committed
51
52
53
    return (
        <>
            <h2 className="border-bottom border-2 text-center pb-2 me-2">현재 영화관 정보</h2>
Kim, Subin's avatar
Kim, Subin committed
54
55
56
57
58
            <div className="mb-3">
                <label for="cinemaName" className="form-label">영화관 이름</label>
                <input type="text" className={`form-control mb-2 ${styles.shadowNone}`} id="cinemaName" name="cinemaName" value={cinemaInfo.cinemaName} onChange={handleChange} />
                <p> 상영관 : 8개관 |  좌석 : 1,282</p>
            </div>
Kim, Subin's avatar
Kim, Subin committed
59
60
            <div className="mb-3">
                <label for="transportation" className="form-label">대중교통 안내</label>
Kim, Subin's avatar
Kim, Subin committed
61
                <textarea className={`form-control ${styles.shadowNone} ${styles.textarea}`} rows="7" id="transportation" name="transportation" value={cinemaInfo.transportation} onChange={handleChange}></textarea>
Kim, Subin's avatar
Kim, Subin committed
62
63
            </div>
            <div className="mb-3">
Kim, Subin's avatar
Kim, Subin committed
64
                <label for="parking" className="form-label">자가용/주차안내</label>
Kim, Subin's avatar
Kim, Subin committed
65
                <textarea className={`form-control ${styles.shadowNone} ${styles.textarea}`} rows="7" id="parking" name="parking" value={cinemaInfo.parking} onChange={handleChange}></textarea>
Kim, Subin's avatar
Kim, Subin committed
66
            </div>
Kim, Subin's avatar
Kim, Subin committed
67
            <label for="keyword" className="form-label">지도보기</label>
Kim, Subin's avatar
Kim, Subin committed
68
            <div className="input-group mb-3">
Kim, Subin's avatar
Kim, Subin committed
69
                <span className="input-group-text" id="address"><i className="bi bi-geo-alt-fill"></i></span>
Kim, Subin's avatar
Kim, Subin committed
70
71
                <input type="text" className={`form-control ${styles.shadowNone}`} id="address" name="address" value={cinemaInfo.address} onChange={handleChange} value={cinemaInfo.address} />
            </div>
72
73
74
75
76
77
78
79
            <p className="mb-0">영화관람료 설정</p>
            <p className="text-danger">*추가금액 정보를 입력바랍니다. 필요에 따라 기본가격 또한 변경 가능합니다.</p>
            <TicketEditForm editFee={ticketFee} />
            <TicketFeeTable editFee={ticketFee} setEditFee={setTicketFee} />
            <div className="mb-3">
                <label for="moreFeeInfo" className="form-label">관람료 추가정보</label>
                <textarea className={`form-control ${styles.shadowNone} ${styles.textarea}`} rows="7" id="moreFeeInfo" name="moreFeeInfo" value={cinemaInfo.moreFeeInfo} onChange={handleChange}></textarea>
            </div>
Kim, Subin's avatar
Kim, Subin committed
80
81
            <div className="d-grid gap-2 mb-5">
                <button type="submit" className={`btn btn-dark shadow-none ${styles.customBtn}`} onClick={handleSubmit}>수정</button>
Kim, Subin's avatar
Kim, Subin committed
82
            </div>
Kim, Subin's avatar
Kim, Subin committed
83
84
85
86
        </>
    )
}
export default CinemaEdit