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

Kim, Subin's avatar
Kim, Subin committed
6
const TicketFeeTable = ({ selectTheater, setEditFee, formRef }) => {
7
8
9
10
    const [ticketFee, setTicketFee] = useState([])
    const [error, setError] = useState("")

    useEffect(() => {
Kim, Subin's avatar
Kim, Subin committed
11
12
        if (selectTheater !== 0) getOne(selectTheater)
    }, [selectTheater])
13

Kim, Subin's avatar
Kim, Subin committed
14
    async function getOne(theatertypeId) {
Kim, Subin's avatar
Kim, Subin committed
15
        try {
Kim, Subin's avatar
Kim, Subin committed
16
17
18
            setError("")
            const res = await cinemaApi.getTicketFeeOne(theatertypeId)
            setTicketFee([res])
Kim, Subin's avatar
Kim, Subin committed
19
20
21
        } catch (error) {
            catchErrors(error, setError)
        }
22
23
    }

24
    async function editRow(theatertypeId) {
25
26
        try {
            setError("")
27
            const res = await cinemaApi.getTicketFeeOne(theatertypeId)
Kim, Subin's avatar
Kim, Subin committed
28
            setEditFee({ ...res })
29
            formRef?.current.scrollIntoView({ behavior: "smooth", block: "center" })
30
31
32
33
34
        } catch (error) {
            catchErrors(error, setError)
        }
    }

35
    async function deleteData(theatertypeId) {
36
37
        try {
            setError("")
38
            await cinemaApi.removeTicketFee(theatertypeId)
39
            alert("해당 관람료 정보를 성공적으로 삭제했습니다.")
Kim, Subin's avatar
Kim, Subin committed
40
            window.location.reload()
41
42
43
44
45
        } catch (error) {
            catchErrors(error, setError)
        }
    }

Kim, Subin's avatar
Kim, Subin committed
46
47
48
49
    function priceToString(price) {
        return price.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    }

50
    return (
Kim, Subin's avatar
Kim, Subin committed
51
        <table className={`table text-center align-middle ${styles.tableForm}`}>
52
            <thead className={`table-dark align-middle ${styles.dNone}`}>
Kim, Subin's avatar
Kim, Subin committed
53
                <tr>
54
                    <th className={styles.word}>상영관 종류</th>
Kim, Subin's avatar
Kim, Subin committed
55
56
57
58
59
                    <th>주중 / 주말</th>
                    <th>시간대</th>
                    <th>청소년</th>
                    <th>일반</th>
                    <th>경로</th>
60
                    <th style={{ width: "14%" }}></th>
Kim, Subin's avatar
Kim, Subin committed
61
62
63
64
65
66
                </tr>
            </thead>
            <tbody>
                {ticketFee.length !== 0 ? ticketFee.map(info =>
                    <>
                        <tr>
67
                            <td rowSpan="6" className={`d-block d-md-table-cell ${styles.Row} ${styles.type}`}>{info.theatertype.theaterTypeName}</td>
68
69
70
71
72
73
                            <td rowSpan="3" className={`d-block d-md-table-cell ${styles.Row} ${styles.moreData}`} data-label="- 청소년 / 성인 / 경로">주중(~)</td>
                            <td className="d-inline-block d-md-table-cell">조조 (06:00 ~ )</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.morning + info.youth + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.morning + info.adult + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.morning + info.senior + info.defaultPrice)}</td>
                            <td rowSpan="6" className="d-none d-md-table-cell">
Kim, Subin's avatar
Kim, Subin committed
74
                                <div className="d-flex flex-column">
75
76
                                    <button type="button" className="btn btn-primary my-1" onClick={() => editRow(info.theatertypeId)}>수정</button>
                                    <button type="button" className="btn btn-danger my-1" onClick={() => deleteData(info.theatertypeId)}>삭제</button>
Kim, Subin's avatar
Kim, Subin committed
77
78
79
80
                                </div>
                            </td>
                        </tr>
                        <tr>
81
82
83
84
                            <td className="d-inline-block d-md-table-cell">일반 (11:00 ~ )</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.day + info.youth + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.day + info.adult + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.day + info.senior + info.defaultPrice)}</td>
Kim, Subin's avatar
Kim, Subin committed
85
86
                        </tr>
                        <tr>
87
88
89
90
                            <td className="d-inline-block d-md-table-cell">심야 (00:00 ~ )</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.night + info.youth + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.night + info.adult + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekdays + info.night + info.senior + info.defaultPrice)}</td>
Kim, Subin's avatar
Kim, Subin committed
91
92
                        </tr>
                        <tr>
93
                            <td rowSpan="3" className={`d-block d-md-table-cell ${styles.Row} ${styles.moreData} ${styles.word}`} data-label="- 청소년 / 성인 / 경로">주말(~)  공휴일</td>
94
95
96
97
                            <td className="d-inline-block d-md-table-cell">조조 (06:00 ~ )</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.morning + info.youth + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.morning + info.adult + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.morning + info.senior + info.defaultPrice)}</td>
Kim, Subin's avatar
Kim, Subin committed
98
99
                        </tr>
                        <tr>
100
101
102
103
                            <td className="d-inline-block d-md-table-cell">일반 (11:00 ~ )</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.day + info.youth + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.day + info.adult + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.day + info.senior + info.defaultPrice)}</td>
Kim, Subin's avatar
Kim, Subin committed
104
                        </tr>
105
106
107
108
109
110
111
                        <tr className={styles.Row}>
                            <td className="d-inline-block d-md-table-cell">심야 (00:00 ~ )</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.night + info.youth + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.night + info.adult + info.defaultPrice)}</td>
                            <td className="d-inline-block d-md-table-cell">{priceToString(info.weekend + info.night + info.senior + info.defaultPrice)}</td>
                            <td className={`d-block d-md-none ${styles.borderTop}`}>
                                <div className="d-flex justify-content-end">
112
113
                                    <button type="button" className="btn btn-primary" onClick={() => editRow(info.theatertypeId)}>수정</button>
                                    <button type="button" className="btn btn-danger ms-2" onClick={() => deleteData(info.theatertypeId)}>삭제</button>
114
115
                                </div>
                            </td>
Kim, Subin's avatar
Kim, Subin committed
116
117
118
                        </tr>
                    </>)
                    : <tr>
Kim, Subin's avatar
Kim, Subin committed
119
                        <td colSpan="7">상단의 상영관을 선택해주십시오.</td>
Kim, Subin's avatar
Kim, Subin committed
120
121
122
                    </tr>}
            </tbody>
        </table>
123
124
125
    )
}

Kim, Subin's avatar
Kim, Subin committed
126
export default TicketFeeTable