|
| 1 | +import { ScaleButton, ScaleHelperText, ScaleIconActionExport, ScaleModal, ScaleTable } from "@telekom/scale-components-react"; |
| 2 | +import { useBoolean } from "ahooks"; |
| 3 | +import { chain } from "lodash"; |
| 4 | +import { Models } from "~/Services/Status.Models"; |
| 5 | +import { useEventExtract } from "./useEventExtract"; |
| 6 | + |
| 7 | +/** |
| 8 | + * @author Aloento |
| 9 | + * @since 1.0.0 |
| 10 | + * @version 0.1.0 |
| 11 | + */ |
| 12 | +export function EventExtract({ Event }: { Event: Models.IEvent }) { |
| 13 | + const { services, setServices, valServices, OnSubmit, Loading } = useEventExtract(Event); |
| 14 | + const [open, { setTrue, setFalse }] = useBoolean(); |
| 15 | + |
| 16 | + return <> |
| 17 | + <ScaleButton onClick={setTrue} size="small" variant="secondary"> |
| 18 | + <ScaleIconActionExport /> |
| 19 | + Extract |
| 20 | + </ScaleButton> |
| 21 | + |
| 22 | + <ScaleModal |
| 23 | + heading="Extract Event" |
| 24 | + opened={open} |
| 25 | + omitCloseButton |
| 26 | + size="small" |
| 27 | + class="absolute" |
| 28 | + onScale-before-close={(e) => e.preventDefault()} |
| 29 | + > |
| 30 | + <form |
| 31 | + className="flex flex-col gap-y-6" |
| 32 | + autoComplete="off" |
| 33 | + onSubmit={(e) => { |
| 34 | + e.preventDefault(); |
| 35 | + OnSubmit().then((ok) => ok && setFalse()); |
| 36 | + }}> |
| 37 | + <ScaleTable> |
| 38 | + <div className="max-h-96 overflow-auto"> |
| 39 | + <table> |
| 40 | + <thead className="sticky"> |
| 41 | + <tr> |
| 42 | + <th /> |
| 43 | + <th>Service Name</th> |
| 44 | + <th>Region</th> |
| 45 | + </tr> |
| 46 | + </thead> |
| 47 | + |
| 48 | + <tbody> |
| 49 | + {chain([...Event.RegionServices]) |
| 50 | + .orderBy(x => x.Service.Name) |
| 51 | + .map((x, i) => |
| 52 | + <tr key={i}> |
| 53 | + <td> |
| 54 | + <input |
| 55 | + type="checkbox" |
| 56 | + onChange={(e) => { |
| 57 | + const checked = e.target.checked; |
| 58 | + setServices((curr) => { |
| 59 | + if (checked) { |
| 60 | + return [...curr, x]; |
| 61 | + } |
| 62 | + |
| 63 | + return curr.filter(s => s !== x); |
| 64 | + }) |
| 65 | + }} |
| 66 | + /> |
| 67 | + </td> |
| 68 | + |
| 69 | + <td>{x.Service.Name}</td> |
| 70 | + <td>{x.Region.Name}</td> |
| 71 | + </tr>) |
| 72 | + .value()} |
| 73 | + </tbody> |
| 74 | + </table> |
| 75 | + </div> |
| 76 | + |
| 77 | + <ScaleHelperText |
| 78 | + variant={valServices ? "danger" : "informational"} |
| 79 | + helperText={valServices || `Selected ${services.length} services`} |
| 80 | + /> |
| 81 | + </ScaleTable> |
| 82 | + |
| 83 | + <div className="flex gap-x-3 self-end"> |
| 84 | + <ScaleButton onClick={setFalse} variant="secondary" type="button"> |
| 85 | + Cancel |
| 86 | + </ScaleButton> |
| 87 | + |
| 88 | + <ScaleButton type="submit" disabled={Loading}> |
| 89 | + Submit |
| 90 | + </ScaleButton> |
| 91 | + </div> |
| 92 | + </form> |
| 93 | + </ScaleModal> |
| 94 | + </>; |
| 95 | +} |
0 commit comments