Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions frontend/src/components/configCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import { Regions } from "./configRegions";
import type { CommonConfig } from "@/types/config";

interface CommonFieldsProps {
commonConfig: CommonConfig;
globalCommonConfig?: CommonConfig; // Unset if common config IS global config
updateCommonConfig: (config: CommonConfig) => void;
config: CommonConfig;
globalConfig?: CommonConfig; // Unset if common config IS global config
updateConfig: (config: CommonConfig) => void;
}

export function CommonFields({
commonConfig: config,
globalCommonConfig: globalConfig,
updateCommonConfig: updateConfig,
config,
globalConfig,
updateConfig,
}: CommonFieldsProps) {
// If fields are for global config, globalConfig will not be set
const isGlobal = !globalConfig;

return (
<div className="space-y-4">
<Regions
value={config.regions}
withGlobalFallback={!!globalConfig}
withGlobalFallback={!isGlobal}
globalFallbackValue={globalConfig?.regions}
updateValue={(value) => {
updateConfig({ ...config, regions: value });
Expand All @@ -31,9 +34,9 @@ export function CommonFields({
type="fraction"
value={config.eventSimilarity}
showReset={true}
resetValue={-1}
resetValue={!isGlobal ? -1 : undefined} // Reset value for global is undefined
defaultValuePlaceholder="0.9"
showGlobalReset={!!globalConfig}
showGlobalReset={!isGlobal}
globalValuePlaceholder={
globalConfig?.eventSimilarity?.toString() || "0.9"
}
Expand All @@ -48,9 +51,9 @@ export function CommonFields({
type="integer"
value={config.numTickets}
showReset={true}
resetValue={-1}
resetValue={!isGlobal ? -1 : undefined} // Reset value for global is undefined
defaultValuePlaceholder="Any"
showGlobalReset={!!globalConfig}
showGlobalReset={!isGlobal}
globalValuePlaceholder={globalConfig?.numTickets?.toString() || "Any"}
updateValue={(value) => {
updateConfig({ ...config, numTickets: value });
Expand All @@ -63,9 +66,9 @@ export function CommonFields({
type="price"
value={config.maxTicketPrice}
showReset={true}
resetValue={-1}
resetValue={!isGlobal ? -1 : undefined} // Reset value for global is undefined
defaultValuePlaceholder="No Max"
showGlobalReset={!!globalConfig}
showGlobalReset={!isGlobal}
globalValuePlaceholder={
globalConfig?.maxTicketPrice?.toString() || "No Max"
}
Expand All @@ -80,9 +83,9 @@ export function CommonFields({
type="percentage"
value={config.discount}
showReset={true}
resetValue={-1}
resetValue={!isGlobal ? -1 : undefined} // Reset value for global is undefined
defaultValuePlaceholder="No Min"
showGlobalReset={!!globalConfig}
showGlobalReset={!isGlobal}
globalValuePlaceholder={
globalConfig?.discount?.toString() || "No Min"
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/configGlobal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function GlobalSettings() {
}
>
<CommonFields
commonConfig={draft}
updateCommonConfig={(commonConfig) => {
config={draft}
updateConfig={(commonConfig) => {
setDraft(commonConfig);
}}
/>
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/configTicket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { Button } from "@/components/ui/button";
import type { CommonConfig, TicketConfig } from "@/types/config";
import { isEqual } from "lodash";
import { Trash, } from "lucide-react";
import { Trash } from "lucide-react";
import { useEffect, useState } from "react";

interface TicketProps {
Expand Down Expand Up @@ -95,7 +95,6 @@ export function Ticket({
<ConfigField
label="Event Name"
description="Name of the event to search for"
placeholder="Enter event name..."
type="text"
value={draft.event}
showReset={false}
Expand All @@ -107,9 +106,9 @@ export function Ticket({
/>

<CommonFields
commonConfig={draft}
globalCommonConfig={globalConfig}
updateCommonConfig={(commonConfig) => {
config={draft}
globalConfig={globalConfig}
updateConfig={(commonConfig) => {
setDraft((prev) => ({ ...prev, ...commonConfig }));
}}
/>
Expand Down