All files / src/components/admin/pro-form-sections LocationSection.tsx

100% Statements 5/5
93.33% Branches 14/15
100% Functions 5/5
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                165x                                                   5x           156x                                 203x           1x                                
import { CollapsibleCard } from "../../ui/collapsible";
import { MultiSelect } from "../../ui/multi-select";
import type { ProFormSectionProps } from "./types";
import { MapPin } from "lucide-react";
 
/**
 * LocationSection component displays location and service area configuration.
 * Includes city selection and service areas/localities.
 */
export function LocationSection({
	pro,
	onUpdateField,
	cities = [],
	localities = [],
	isLoadingTaxonomy = false,
}: ProFormSectionProps) {
	return (
		<CollapsibleCard
			title="Location"
			description="Where does this business operate?"
			icon={<MapPin className="h-5 w-5" />}
			defaultOpen={!!pro.cityId}
		>
			<div className="space-y-4 pt-4">
				{isLoadingTaxonomy ? (
					<div className="animate-pulse space-y-4">
						<div className="h-10 bg-background-muted rounded" />
						<div className="h-10 bg-background-muted rounded" />
					</div>
				) : (
					<>
						<div className="space-y-2">
							<label
								htmlFor="admin-city"
								className="text-sm font-medium text-foreground-default"
							>
								City
							</label>
							<select
								id="admin-city"
								value={pro.cityId || ""}
								onChange={(e) =>
									onUpdateField("cityId", e.target.value || null)
								}
								className="flex h-10 w-full rounded-md border border-border-default bg-background-elevated px-3 py-2 text-sm text-foreground-default focus:outline-none focus:ring-2 focus:ring-primary-500/40 focus:border-primary-500"
							>
								<option value="">Select a city</option>
								{cities.map((c) => (
									<option key={c.id} value={c.id}>
										{c.name}
									</option>
								))}
							</select>
						</div>
						<div className="space-y-2">
							<label
								htmlFor="admin-service-areas"
								id="admin-service-areas-label"
								className="text-sm font-medium text-foreground-default"
							>
								Service Areas / Localities
							</label>
							<MultiSelect
								id="admin-service-areas"
								aria-labelledby="admin-service-areas-label"
								options={localities.map((l) => ({
									value: l.id,
									label: l.name,
								}))}
								selected={pro.serviceAreaIds || []}
								onChange={(values) =>
									onUpdateField(
										"serviceAreaIds",
										values.length > 0 ? values : null,
									)
								}
								placeholder={
									pro.cityId ? "Select service areas" : "Select a city first"
								}
							/>
						</div>
					</>
				)}
			</div>
		</CollapsibleCard>
	);
}