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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | 39x 39x 39x 5x 39x 3x 39x 3x 39x 3x 39x 39x 39x 39x 39x 39x 39x 2x 2x 1x 39x 3x 2x 2x 1x 1x | import { useState } from "react";
import { Building2, MapPin, FileText } from "lucide-react";
import type { Pro, City, Locality } from "../../../lib/api";
import { useUpdateProProfile } from "../../../hooks/mutations/useProMutations";
import { SectionCard } from "../SectionCard";
import { ReadOnlyField } from "../ReadOnlyField";
import { BusinessDetailsModal, TEAM_SIZES, LANGUAGES } from "../modals/BusinessDetailsModal";
import { LocationModal } from "../modals/LocationModal";
import { AboutModal } from "../modals/AboutModal";
interface BusinessBasicsTabProps {
pro: Pro;
proId: string;
cities: City[];
localities: Locality[];
onCityChange: (cityId: string) => void;
/** #362: hide Edit affordances for roles the backend will 403 on save. */
canEdit?: boolean;
}
export function BusinessBasicsTab({
pro,
proId,
cities,
localities,
onCityChange,
canEdit = true,
}: BusinessBasicsTabProps) {
const updateProfile = useUpdateProProfile(proId);
const [editingSection, setEditingSection] = useState<
"details" | "location" | "about" | null
>(null);
// Look up display values
const cityName = pro.cityId
? cities.find((c) => c.id === pro.cityId)?.name || null
: pro.addressCity || null;
const serviceAreaNames = (pro.serviceAreaIds || [])
.map((id) => localities.find((l) => l.id === id)?.name)
.filter(Boolean) as string[];
const teamSizeLabel = pro.teamSize
? TEAM_SIZES.find((t) => t.value === pro.teamSize)?.label || pro.teamSize
: null;
const languageLabels = (pro.languagesSpoken || [])
.map((v) => LANGUAGES.find((l) => l.value === v)?.label || v);
const yearsDisplay = pro.yearsInBusiness != null
? `${pro.yearsInBusiness} year${pro.yearsInBusiness === 1 ? "" : "s"}`
: null;
// Build full address string
const addressParts = [
pro.addressLine1,
pro.addressLine2,
pro.addressCity,
pro.addressState,
pro.addressPincode,
].filter(Boolean);
const fullAddress = addressParts.length > 0 ? addressParts.join(", ") : null;
// isEmpty checks
const isDetailsEmpty = !pro.businessName;
const isLocationEmpty = !pro.cityId && !pro.addressCity && !pro.addressLine1;
const isAboutEmpty = !pro.tagline && !pro.about && !pro.processDescription;
const handleSave = async (data: Partial<Pro>) => {
try {
await updateProfile.mutateAsync(data);
setEditingSection(null);
} catch {
// Error toast shown by mutation onError callback
}
};
return (
<div className="grid grid-cols-1 xl:grid-cols-2 gap-6">
{/* Business Details */}
<SectionCard
title="Business Details"
icon={<Building2 className="h-5 w-5" />}
onEdit={canEdit ? () => setEditingSection("details") : undefined}
isEmpty={isDetailsEmpty}
>
<dl className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<ReadOnlyField label="Business Name" value={pro.businessName} />
<ReadOnlyField label="Business Identifier" value={pro.slug} />
<ReadOnlyField label="Years in Business" value={yearsDisplay} />
<ReadOnlyField label="Team Size" value={teamSizeLabel} />
<ReadOnlyField
label="Languages Spoken"
value={languageLabels.length > 0 ? languageLabels : null}
className="sm:col-span-2"
/>
</dl>
</SectionCard>
{/* Location */}
<SectionCard
title="Location"
icon={<MapPin className="h-5 w-5" />}
onEdit={canEdit ? () => setEditingSection("location") : undefined}
isEmpty={isLocationEmpty}
>
<dl className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<ReadOnlyField label="City" value={cityName} />
<ReadOnlyField
label="Service Areas"
value={serviceAreaNames.length > 0 ? serviceAreaNames : null}
className="sm:col-span-2"
/>
<ReadOnlyField
label="Address"
value={fullAddress}
className="sm:col-span-2"
/>
</dl>
</SectionCard>
{/* About / Description */}
<SectionCard
title="About / Description"
icon={<FileText className="h-5 w-5" />}
onEdit={canEdit ? () => setEditingSection("about") : undefined}
isEmpty={isAboutEmpty}
className="xl:col-span-2"
>
<dl className="grid grid-cols-1 gap-4">
<ReadOnlyField label="Tagline" value={pro.tagline} />
<ReadOnlyField label="About" value={pro.about} />
<ReadOnlyField label="Process Description" value={pro.processDescription} />
</dl>
</SectionCard>
{/* Modals */}
{editingSection === "details" && (
<BusinessDetailsModal
pro={pro}
onSave={handleSave}
onClose={() => setEditingSection(null)}
/>
)}
{editingSection === "location" && (
<LocationModal
pro={pro}
cities={cities}
localities={localities}
onCityChange={onCityChange}
onSave={handleSave}
onClose={() => setEditingSection(null)}
/>
)}
{editingSection === "about" && (
<AboutModal
pro={pro}
onSave={handleSave}
onClose={() => setEditingSection(null)}
/>
)}
</div>
);
}
|