From 9c30ea5f517c77f50911425d52a8d9169657ea27 Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Wed, 6 May 2026 20:06:05 +0300 Subject: [PATCH 1/2] Generalize segment modal form elements --- .../js/dashboard/segments/segment-modals.tsx | 101 +++++++++++------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/assets/js/dashboard/segments/segment-modals.tsx b/assets/js/dashboard/segments/segment-modals.tsx index 424e7e4145b2..fc5a22281e77 100644 --- a/assets/js/dashboard/segments/segment-modals.tsx +++ b/assets/js/dashboard/segments/segment-modals.tsx @@ -29,6 +29,24 @@ import { Button, buttonClassName } from '../components/button' const inModalSectionLabelClassName = 'text-sm font-semibold dark:text-gray-100' +const nameInputProps = { id: 'name', label: 'Segment name' } + +const segmentTypeSelectorProps = { + idPrefix: 'segment-type', + options: [ + { + type: SegmentType.personal, + name: SEGMENT_TYPE_LABELS[SegmentType.personal], + description: 'Visible only to you' + }, + { + type: SegmentType.site, + name: SEGMENT_TYPE_LABELS[SegmentType.site], + description: 'Visible to others on the site' + } + ] +} + interface ApiRequestProps { status: MutationStatus error?: unknown @@ -79,18 +97,23 @@ export const CreateSegmentModal = ({ return ( - - - {disabled && } + + {...segmentTypeSelectorProps} + value={type} + onChange={onSegmentTypeChange} + /> + {disabled && } - { const trimmedName = name.trim() @@ -254,55 +277,50 @@ const RelatedSharedLinks = ({ sharedLinks }: { sharedLinks: string[] }) => { ) } -const SegmentNameInput = ({ - namePlaceholder, +export const LabeledTextInput = ({ + label, + id, value, - onChange + onChange, + placeholder }: { - namePlaceholder: string + label: string + id: string value: string onChange: (value: string) => void + placeholder: string }) => { return (
onChange(e.target.value)} - placeholder={namePlaceholder} - id="name" + placeholder={placeholder} + id={id} className="block px-3.5 py-2.5 w-full text-sm dark:text-gray-300 rounded-md border border-gray-300 dark:border-gray-750 dark:bg-gray-750 focus:outline-none focus:ring-3 focus:ring-indigo-500/20 dark:focus:ring-indigo-500/25 focus:border-indigo-500" />
) } -const SegmentTypeSelector = ({ +export const TypeSelector = ({ value, - onChange + onChange, + options, + idPrefix }: { - value: SegmentType - onChange: (value: SegmentType) => void + value: T + onChange: (value: T) => void + options: { type: T; name: string; description: string }[] + idPrefix: string }) => { - const options = [ - { - type: SegmentType.personal, - name: SEGMENT_TYPE_LABELS[SegmentType.personal], - description: 'Visible only to you' - }, - { - type: SegmentType.site, - name: SEGMENT_TYPE_LABELS[SegmentType.site], - description: 'Visible to others on the site' - } - ] - return (
{options.map(({ type, name, description }) => ( @@ -310,14 +328,14 @@ const SegmentTypeSelector = ({
onChange(type)} className="mt-px size-4.5 cursor-pointer text-indigo-600 dark:bg-transparent border-gray-400 dark:border-gray-600 checked:border-indigo-600 dark:checked:border-white" />