TicketFeeTable.js 8.2 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
5
import { useAuth } from '../../context/auth_context'

6
import styles from "./admin.module.scss";
7

8
const TicketFeeTable = ({ setEditFee, formRef }) => {
9
10
    const [ticketFee, setTicketFee] = useState([])
    const [error, setError] = useState("")
11
12
    const { user } = useAuth()

13
14
15
16
17
18

    useEffect(() => {
        getInfo()
    }, [])

    async function getInfo() {
Kim, Subin's avatar
Kim, Subin committed
19
20
21
22
23
24
        try {
            const res = await cinemaApi.getTicketFee()
            setTicketFee(res)
        } catch (error) {
            catchErrors(error, setError)
        }
25
26
    }

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

38
    async function deleteData(theatertypeId) {
39
40
        try {
            setError("")
41
            await cinemaApi.removeTicketFee(theatertypeId)
42
43
44
45
46
47
48
            alert("해당 관람료 정보를 성공적으로 삭제했습니다.")
            getInfo()
        } catch (error) {
            catchErrors(error, setError)
        }
    }

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

53
    return (
54
        <table style={{ color: user.role==="admin"?"":"white" }} className={`table caption-top text-center align-middle ${styles.tableForm}`}>
Kim, Subin's avatar
Kim, Subin committed
55
            <caption className="text-dark">영화관람료 안내</caption>
56
            <thead className={`table-dark align-middle ${styles.dNone}`}>
Kim, Subin's avatar
Kim, Subin committed
57
                <tr>
58
                    <th className={styles.word}>상영관 종류</th>
Kim, Subin's avatar
Kim, Subin committed
59
60
61
62
63
                    <th>주중 / 주말</th>
                    <th>시간대</th>
                    <th>청소년</th>
                    <th>일반</th>
                    <th>경로</th>
64
65
66
67
                    {user.role === "admin"
                        ?
                        <th style={{ width: "14%" }}></th>
                        : <></>}
Kim, Subin's avatar
Kim, Subin committed
68
69
70
71
72
73
                </tr>
            </thead>
            <tbody>
                {ticketFee.length !== 0 ? ticketFee.map(info =>
                    <>
                        <tr>
74
                            <td rowSpan="6" className={`d-block d-md-table-cell ${styles.Row} ${styles.type}`}>{info.theatertype.theaterTypeName}</td>
75
76
77
78
79
                            <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>
80
81
82
83
84
85
86
87
88
                            {user.role === "admin"
                                ?
                                <td rowSpan="6" className="d-none d-md-table-cell">
                                    <div className="d-flex flex-column">
                                        <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>
                                    </div>
                                </td>
                                : <></>}
Kim, Subin's avatar
Kim, Subin committed
89
90
                        </tr>
                        <tr>
91
92
93
94
                            <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
95
96
                        </tr>
                        <tr>
97
98
99
100
                            <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
101
102
                        </tr>
                        <tr>
103
                            <td rowSpan="3" className={`d-block d-md-table-cell ${styles.Row} ${styles.moreData} ${styles.word}`} data-label="- 청소년 / 성인 / 경로">주말(~)  공휴일</td>
104
105
106
107
                            <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
108
109
                        </tr>
                        <tr>
110
111
112
113
                            <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
114
                        </tr>
115
116
117
118
119
                        <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>
120
121
122
123
124
125
126
127
128
                            {user.role === "admin"
                                ?
                                <td className={`d-block d-md-none ${styles.borderTop}`}>
                                    <div className="d-flex justify-content-end">
                                        <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>
                                    </div>
                                </td>
                                : <></>}
Kim, Subin's avatar
Kim, Subin committed
129
130
131
132
133
134
135
                        </tr>
                    </>)
                    : <tr>
                        <td colSpan="7">등록된 관람료 관련 정보가 없습니다.</td>
                    </tr>}
            </tbody>
        </table>
136
137
138
    )
}

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