Skip to content

Commit 4a7f005

Browse files
committed
Feat: added free seating checkbox
1 parent 4ab4e6f commit 4a7f005

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { useCallback } from "react";
12
import { useSelector } from "react-redux";
2-
import { selectPolylineById } from "@/store/reducers/editor";
3+
import { Checkbox } from "@/components/core";
4+
import { store } from "@/store";
5+
import { selectPolylineById, updatePolyline } from "@/store/reducers/editor";
36
import { d3Extended, rgbToHex } from "@/utils";
47
import { default as ControlInput } from "../../control-input";
58
import { default as SectionSelector } from "./section-selector";
@@ -8,6 +11,16 @@ const PolylineSelectControls = () => {
811
const selectedElementIds = useSelector((state: any) => state.editor.selectedElementIds);
912
const firstPolyline = useSelector(selectPolylineById(selectedElementIds[0]));
1013
const firstElement = document.getElementById(selectedElementIds[0]);
14+
15+
const onCheckedChange = useCallback(
16+
(value: boolean) => {
17+
selectedElementIds.forEach((id: string) => {
18+
store.dispatch(updatePolyline({ id, freeSeating: value }));
19+
});
20+
},
21+
[selectedElementIds]
22+
);
23+
1124
return (
1225
<div className="flex flex-col gap-4 py-1">
1326
<SectionSelector firstElement={firstElement} selectedElementIds={selectedElementIds} />
@@ -36,6 +49,20 @@ const PolylineSelectControls = () => {
3649
});
3750
}}
3851
/>
52+
<div className="col-span-3 w-full flex justify-end items-center gap-[2.3rem]">
53+
<Checkbox
54+
id="stk-free-section-marker"
55+
checked={firstPolyline.freeSeating}
56+
onCheckedChange={onCheckedChange}
57+
disabled={!!firstPolyline.section}
58+
/>
59+
<label
60+
htmlFor="stk-free-section-marker"
61+
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
62+
>
63+
Free seating section
64+
</label>
65+
</div>
3966
</div>
4067
</div>
4168
);

src/components/workspace/elements/polyline.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
import { forwardRef, useMemo } from "react";
22
import { twMerge } from "tailwind-merge";
33
import { dataAttributes } from "@/constants";
4-
import { IPolyline, ISection } from "@/types";
4+
import { IPolyline, ISTKProps, ISection } from "@/types";
55

66
export interface IPolylineProps extends IPolyline {
77
className?: string;
8+
consumer: ISTKProps;
89
sections?: ISection[];
10+
onClick: (e: any) => void;
911
}
1012

1113
const Polyline: React.FC<IPolylineProps> = forwardRef(
12-
({ id, points, color, stroke, sections, section, ...props }, ref: any) => {
14+
({ id, points, color, stroke, sections, section, onClick, consumer, ...props }, ref: any) => {
1315
const sectionObject = useMemo(() => sections?.find?.((s) => s.id === section), [sections, section]);
16+
17+
const localOnClick = (e) => {
18+
onClick(e);
19+
consumer.events?.onSectionClick?.(sectionObject);
20+
};
21+
1422
return (
1523
<polyline
1624
ref={ref}
1725
id={id}
1826
points={points.map((p) => `${p.x},${p.y}`).join(" ")}
27+
onClick={localOnClick}
1928
{...props}
2029
style={{ color: sectionObject?.color ?? color ?? "transparent", stroke: sectionObject?.stroke ?? stroke }}
2130
{...{ [dataAttributes.section]: section }}

0 commit comments

Comments
 (0)