Skip to content

Commit 9dcfdd2

Browse files
committed
Feat: added seat status colors
1 parent 8bbad41 commit 9dcfdd2

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

src/components/controls/select/seats/index.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useSelector } from "react-redux";
22
import { Label, RadioGroup, RadioGroupItem } from "@/components/core";
3-
import { SeatStatus, dataAttributes } from "@/constants";
3+
import { SeatStatus, dataAttributes, seatStatusColors } from "@/constants";
44
import { store } from "@/store";
55
import { updateSeat } from "@/store/reducers/editor";
66
import { d3Extended } from "@/utils";
@@ -34,7 +34,22 @@ const SeatSelectControls = () => {
3434
defaultValue={firstElement?.getAttribute(dataAttributes.status) ?? SeatStatus.Available.toString()}
3535
onValueChange={(value) => {
3636
selectedElementIds.forEach((id: string) => {
37-
d3Extended.selectById(id).attr(dataAttributes.status, value);
37+
const seat = d3Extended.selectById(id);
38+
const seatLabel = d3Extended.selectById(`${id}-label`);
39+
seat.attr(dataAttributes.status, value);
40+
let color = seatStatusColors[value].background;
41+
let textColor = seatStatusColors[value].label;
42+
if (value === SeatStatus.Available) {
43+
const category = store
44+
.getState()
45+
.editor.categories.find((c) => c.id === seat.attr(dataAttributes.category));
46+
if (category) {
47+
color = category.color;
48+
textColor = category.textColor;
49+
}
50+
}
51+
seat.style("color", color, "important");
52+
seatLabel?.style("stroke", textColor, "important");
3853
});
3954
}}
4055
className="flex justify-between gap-2 my-1"

src/components/workspace/elements/seat.jsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { forwardRef, useEffect } from "react";
1+
import { forwardRef, useEffect, useMemo } from "react";
22
import { twMerge } from "tailwind-merge";
3-
import { dataAttributes } from "@/constants";
3+
import { SeatStatus, dataAttributes, seatStatusColors } from "@/constants";
44
import { d3Extended } from "@/utils";
55

66
export const seatSize = 28;
@@ -14,12 +14,22 @@ const Seat = forwardRef(({ x, y, id, label, categories, category, status, ...pro
1414

1515
if (labelLength >= 2) textX -= (seatLabelFontSize / 2.75) * (labelLength - 1);
1616

17-
const categoryObject = categories?.find?.((c) => c.id === category);
17+
const categoryObject = useMemo(() => categories?.find?.((c) => c.id === category), [categories, category]);
1818

1919
useEffect(() => {
20-
if (ref.current && categoryObject) {
21-
d3Extended.select(ref.current).style("color", categoryObject.color, "important");
22-
d3Extended.selectById(`${id}-label`).style("stroke", categoryObject.textColor, "important");
20+
if (ref.current) {
21+
const seat = d3Extended.select(ref.current);
22+
const seatLabel = d3Extended.selectById(`${id}-label`);
23+
const status = seat.attr(dataAttributes.status);
24+
if (status === SeatStatus.Unavailable || status === SeatStatus.Reserved) {
25+
seat.style("color", seatStatusColors[status].background, "important");
26+
seatLabel?.style("stroke", seatStatusColors[status].label, "important");
27+
} else {
28+
if (categoryObject) {
29+
seat.style("color", categoryObject.color, "important");
30+
seatLabel?.style("stroke", categoryObject.textColor, "important");
31+
}
32+
}
2333
}
2434
}, [ref, categoryObject]);
2535

src/constants/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,18 @@ export enum SeatStatus {
3030
Unavailable = "Unavailable",
3131
Reserved = "Reserved"
3232
}
33+
34+
export const seatStatusColors = {
35+
[SeatStatus.Available]: {
36+
background: "#ffffff",
37+
label: "#000000"
38+
},
39+
[SeatStatus.Unavailable]: {
40+
background: "#e0e0e0",
41+
label: "#000000"
42+
},
43+
[SeatStatus.Reserved]: {
44+
background: "#ff0000",
45+
label: "#ffffff"
46+
}
47+
};

0 commit comments

Comments
 (0)