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

100% Statements 8/8
93.75% Branches 15/16
100% Functions 5/5
100% Lines 7/7

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                    154x 41x 41x                     154x                                       3x                               3x                                 3x                      
import { CollapsibleCard } from "../../ui/collapsible";
import { Input } from "../../ui/input";
import type { ProFormSectionProps } from "./types";
import { Phone } from "lucide-react";
import { parseIndianPhone } from "@interioring/utils/validation/phone";
 
// Stored values are E.164 (e.g. "+919876543210") but the admin input shows the
// 10-digit national portion. Strip "+91" on read; let the API's Zod schema
// re-normalize on write.
function displayPhone(stored: string | null | undefined): string {
	if (!stored) return "";
	const parsed = parseIndianPhone(stored);
	return parsed ? parsed.e164.slice(3) : stored;
}
 
/**
 * ContactDetailsSection component displays contact information.
 * Includes alternate phone, email, and business address fields.
 */
export function ContactDetailsSection({
	pro,
	onUpdateField,
}: ProFormSectionProps) {
	return (
		<CollapsibleCard
			title="Contact Details"
			description="How customers can reach this pro"
			icon={<Phone className="h-5 w-5" />}
			defaultOpen={!!pro.email || !!pro.phoneAlternate}
		>
			<div className="space-y-4 pt-4">
				<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
					<div className="space-y-2">
						<label
							htmlFor="admin-phone-alternate"
							className="text-sm font-medium text-foreground-default"
						>
							Alternate Phone
						</label>
						<Input
							id="admin-phone-alternate"
							value={displayPhone(pro.phoneAlternate)}
							onChange={(e) =>
								onUpdateField("phoneAlternate", e.target.value || null)
							}
							placeholder="Alternate contact number"
							type="tel"
						/>
					</div>
					<div className="space-y-2">
						<label
							htmlFor="admin-email"
							className="text-sm font-medium text-foreground-default"
						>
							Email
						</label>
						<Input
							id="admin-email"
							value={pro.email || ""}
							onChange={(e) => onUpdateField("email", e.target.value || null)}
							placeholder="business@example.com"
							type="email"
						/>
					</div>
				</div>
				<div className="space-y-2">
					<label
						htmlFor="admin-business-address"
						className="text-sm font-medium text-foreground-default"
					>
						Business Address
					</label>
					<textarea
						id="admin-business-address"
						value={pro.businessAddress || ""}
						onChange={(e) =>
							onUpdateField("businessAddress", e.target.value || null)
						}
						placeholder="Enter business address"
						className="flex min-h-[80px] w-full rounded-md border border-border-default bg-background-elevated px-3 py-2 text-sm text-foreground-default placeholder:text-foreground-subtle focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent"
						rows={3}
					/>
				</div>
			</div>
		</CollapsibleCard>
	);
}