Skip to content

Commit

Permalink
Feat: added support for max seat selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Apr 7, 2024
1 parent 75415bc commit cdf9cbb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/components/workspace/elements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ export const Element: React.FC<IElementProps> = ({
}, [ref, consumer.mode]);

const onClick = (e: any) => {
if (
consumer.mode === "user" &&
(type !== ElementType.Seat || (props.status && props.status !== SeatStatus.Available))
) {
return;
if (consumer.mode === "user") {
if (type !== ElementType.Seat || props.status !== SeatStatus.Available) {
return;
}
if (
consumer.options?.maxSeatSelectionCount &&
store.getState().editor.selectedElementIds.length > consumer.options?.maxSeatSelectionCount
) {
return consumer.events?.onMaxSeatSelectionCountReached?.();
}
}
if (consumer.mode === "user" && consumer.seatSelectionMode === "chain") {
if (isSelected) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/workspace/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback } from "react";
import { useSelector } from "react-redux";
import { twMerge } from "tailwind-merge";
import { dataAttributes, ids } from "@/constants";
import { type ISTKProps } from "@/types";
import { type ISTKProps, SeatStatus } from "@/types";
import { Tool, tools } from "../toolbar/data";
import { default as Crosshairs } from "./crosshairs";
import { default as Element, ElementType } from "./elements";
Expand Down Expand Up @@ -74,7 +74,7 @@ export const Workspace: React.FC<ISTKProps> = (props) => {
sections={sections}
categories={categories}
category={e.category}
status={e.status}
status={e.status ?? SeatStatus.Available}
{...elementProps(e)}
/>
))}
Expand Down
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface IEvents {
onSeatLeave?: (seat: IPopulatedSeat, coords: ICoordinates) => void;
/** Only applicable in user mode */
onSeatSelectionChange?: (seats: IPopulatedSeat[]) => void;
/** Only applicable in user mode. Fired when the user tries to select more seats than the maxSeatSelectionCount */
onMaxSeatSelectionCountReached?: () => void;
onWorkspaceHover?: () => void;
onSectionClick?: (section: ISection) => void;
onExport?: (data: ISTKData) => void;
Expand Down Expand Up @@ -72,5 +74,7 @@ export interface ISTKProps {
operationTriggerIcon?: React.FC;
seatIcon?: React.FC<any>;
selectedSeatIcon?: React.FC<any>;
/** Only applicable in user mode. If provided, will stop the user from selecting more seats than the provided number. */
maxSeatSelectionCount?: number;
};
}

0 comments on commit cdf9cbb

Please sign in to comment.