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

Kim, Subin's avatar
Kim, Subin committed
6
7
8
9
10
11
12
const INIT_CINEMAINFO = {
    cinemaName: "", 
    transportation: "", 
    parking: "", 
    address: "" 
}

Kim, Subin's avatar
Kim, Subin committed
13
const CinemaEdit = () => {
Kim, Subin's avatar
Kim, Subin committed
14
15
16
17
18
19
    const [cinemaInfo, setCinemaInfo] = useState(INIT_CINEMAINFO)
    const [error, setError] = useState("")

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

Kim, Subin's avatar
Kim, Subin committed
21
22
    function handleChange(e) {
        const { name, value } = e.target
Kim, Subin's avatar
Kim, Subin committed
23
        setCinemaInfo({ ...cinemaInfo, [name]: value })
Kim, Subin's avatar
Kim, Subin committed
24
25
    }

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

    async function handleSubmit() {
        try {
            setError("")
            await cinemaApi.edit(cinemaInfo)
            window.location.reload()
        } catch (error) {
            catchErrors(error, setError)
        }
    }

Kim, Subin's avatar
Kim, Subin committed
47
48
49
    return (
        <>
            <h2 className="border-bottom border-2 text-center pb-2 me-2">현재 영화관 정보</h2>
Kim, Subin's avatar
Kim, Subin committed
50
51
52
53
54
            <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
55
56
            <div className="mb-3">
                <label for="transportation" className="form-label">대중교통 안내</label>
Kim, Subin's avatar
Kim, Subin committed
57
                <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
58
59
            </div>
            <div className="mb-3">
Kim, Subin's avatar
Kim, Subin committed
60
                <label for="parking" className="form-label">자가용/주차안내</label>
Kim, Subin's avatar
Kim, Subin committed
61
                <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
62
            </div>
Kim, Subin's avatar
Kim, Subin committed
63
            <label for="keyword" className="form-label">지도보기</label>
Kim, Subin's avatar
Kim, Subin committed
64
            <div className="input-group mb-3">
Kim, Subin's avatar
Kim, Subin committed
65
                <span className="input-group-text" id="address"><i className="bi bi-geo-alt-fill"></i></span>
Kim, Subin's avatar
Kim, Subin committed
66
67
68
69
                <input type="text" className={`form-control ${styles.shadowNone}`} id="address" name="address" value={cinemaInfo.address} onChange={handleChange} value={cinemaInfo.address} />
            </div>
            <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
70
            </div>
Kim, Subin's avatar
Kim, Subin committed
71
72
73
74
        </>
    )
}
export default CinemaEdit