|
| 1 | +import { useState } from "react"; |
| 2 | + |
| 3 | +export default function WorkerTable({ |
| 4 | + worker_list, |
| 5 | + isDetail = false, // "현재 위치" 포함 여부 (Y=false, N=true) |
| 6 | + selectWorker, |
| 7 | + openModal, |
| 8 | + isManager = false, |
| 9 | +}) { |
| 10 | + const [searchType, setSearchType] = useState("byName"); |
| 11 | + const [search, setSearch] = useState(""); |
| 12 | + const [selectedStatus, setSelectedStatus] = useState("전체"); |
| 13 | + |
| 14 | + const filteredWorkers = worker_list.filter((worker) => { |
| 15 | + if (searchType === "byName") { |
| 16 | + return worker.name.includes(search.trim()); |
| 17 | + } else if (searchType === "byStatus") { |
| 18 | + if (selectedStatus === "전체") { |
| 19 | + return worker_list; |
| 20 | + } |
| 21 | + return worker.status === selectedStatus; |
| 22 | + } |
| 23 | + return true; |
| 24 | + }); |
| 25 | + |
| 26 | + const directCall = (email, phone) => { |
| 27 | + const confirmed = window.confirm(`작업자를 호출하시겠습니까?`); |
| 28 | + if (confirmed) { |
| 29 | + /* To-Do: 긴급 호출 기능 구현하면 됨!! */ |
| 30 | + console.log("긴급 호출!!!!!", `${email} ${phone}`); |
| 31 | + } |
| 32 | + }; |
| 33 | + return ( |
| 34 | + <> |
| 35 | + <div className="table-container"> |
| 36 | + <table className="worker-table"> |
| 37 | + <thead> |
| 38 | + {!isManager && ( |
| 39 | + <tr className="table-search"> |
| 40 | + <th colSpan={6}> |
| 41 | + <div className="search-container"> |
| 42 | + {/* 이름검색 라디오버튼 */} |
| 43 | + <div> |
| 44 | + <label> |
| 45 | + <input |
| 46 | + className="radio" |
| 47 | + type="radio" |
| 48 | + name="searchType" |
| 49 | + value="byName" |
| 50 | + checked={searchType == "byName"} |
| 51 | + onChange={() => { |
| 52 | + setSearchType("byName"); |
| 53 | + setSearch(""); |
| 54 | + }} |
| 55 | + ></input> |
| 56 | + 이름으로 검색 |
| 57 | + </label> |
| 58 | + <input |
| 59 | + id="search" |
| 60 | + name="search" |
| 61 | + className="search-field" |
| 62 | + value={search} |
| 63 | + onChange={(e) => setSearch(e.target.value)} |
| 64 | + disabled={searchType !== "byName"} |
| 65 | + /> |
| 66 | + </div> |
| 67 | + {/* 상태별 분류 라디오버튼 */} |
| 68 | + <div> |
| 69 | + <label> |
| 70 | + <input |
| 71 | + className="radio" |
| 72 | + type="radio" |
| 73 | + name="searchType" |
| 74 | + value="byStatus" |
| 75 | + checked={searchType == "byStatus"} |
| 76 | + onChange={() => { |
| 77 | + setSearchType("byStatus"); |
| 78 | + setSelectedStatus("전체"); |
| 79 | + }} |
| 80 | + ></input> |
| 81 | + 상태별 분류 |
| 82 | + </label> |
| 83 | + <select |
| 84 | + id="status" |
| 85 | + className="search-field" |
| 86 | + value={selectedStatus} |
| 87 | + onChange={(e) => setSelectedStatus(e.target.value)} |
| 88 | + disabled={searchType !== "byStatus"} |
| 89 | + > |
| 90 | + <option value="전체">전체</option> |
| 91 | + <option value="정상">정상</option> |
| 92 | + <option value="위험">위험</option> |
| 93 | + </select> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + </th> |
| 97 | + </tr> |
| 98 | + )} |
| 99 | + <tr className="table-header"> |
| 100 | + <th>상태</th> |
| 101 | + <th>이름</th> |
| 102 | + {!isDetail && <th>현재 위치</th>} |
| 103 | + <th className="id-row">웨어러블 ID</th> |
| 104 | + <th>연락처</th> |
| 105 | + <th>호출</th> |
| 106 | + </tr> |
| 107 | + </thead> |
| 108 | + <tbody> |
| 109 | + {filteredWorkers.map((worker, i) => { |
| 110 | + let tmp = ""; |
| 111 | + if (worker.status == "위험") { |
| 112 | + tmp = "critical"; |
| 113 | + } |
| 114 | + return ( |
| 115 | + <tr key={i} className={tmp}> |
| 116 | + <td>{worker.status}</td> |
| 117 | + <td>{worker.name}</td> |
| 118 | + {!isDetail && <td>{worker.zone}</td>} |
| 119 | + <td className="id-row">{worker.wearableId}</td> |
| 120 | + <td |
| 121 | + style={{ cursor: "pointer", textDecoration: "underline" }} |
| 122 | + onClick={() => { |
| 123 | + selectWorker(worker); |
| 124 | + openModal(true); |
| 125 | + }} |
| 126 | + > |
| 127 | + 조회 |
| 128 | + </td> |
| 129 | + <td |
| 130 | + style={{ fontSize: "1.2rem", cursor: "pointer" }} |
| 131 | + onClick={() => directCall(worker.email, worker.phone)} |
| 132 | + > |
| 133 | + 🚨 |
| 134 | + </td> |
| 135 | + </tr> |
| 136 | + ); |
| 137 | + })} |
| 138 | + </tbody> |
| 139 | + </table> |
| 140 | + </div> |
| 141 | + </> |
| 142 | + ); |
| 143 | +} |
0 commit comments