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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | 33x 33x 33x 33x 33x 33x 2x 2x 1x 33x 33x 4x 2x 1x 1x 1x 1x | import { Image, Phone, Share2 } from "lucide-react";
import { useState } from "react";
import { useUpdateProProfile } from "../../../hooks/mutations/useProMutations";
import type { Pro } from "../../../lib/api";
import { getImageUrl } from "../../../lib/api";
import { ContactDetailsModal } from "../modals/ContactDetailsModal";
import { CoverImageModal } from "../modals/CoverImageModal";
import { LogoModal } from "../modals/LogoModal";
import { SocialMediaModal } from "../modals/SocialMediaModal";
import { ReadOnlyField } from "../ReadOnlyField";
import { SectionCard } from "../SectionCard";
import { WhatsAppRecipientsCard } from "../whatsapp-recipients/WhatsAppRecipientsCard";
interface SocialContactTabProps {
pro: Pro;
proId: string;
/** #362: hide Edit affordances for roles the backend will 403 on save. */
canEdit?: boolean;
}
export function SocialContactTab({ pro, proId, canEdit = true }: SocialContactTabProps) {
const updateProfile = useUpdateProProfile(proId);
const [editingSection, setEditingSection] = useState<
"contact" | "social" | "logo" | "cover" | null
>(null);
const isContactEmpty =
!pro.whatsapp &&
!pro.whatsappBusinessNumber &&
!pro.phoneAlternate &&
!pro.email;
const isSocialEmpty =
!pro.instagramHandle &&
!pro.websiteUrl &&
!pro.googleBusinessUrl &&
!pro.facebookUrl &&
!pro.youtubeUrl &&
!pro.linkedinUrl &&
!pro.twitterUrl &&
!pro.pinterestUrl;
const isImagesEmpty = !pro.logoUrl && !pro.coverImage;
const handleSave = async (data: Partial<Pro>) => {
try {
await updateProfile.mutateAsync(data);
setEditingSection(null);
} catch {
// Error toast shown by mutation onError callback
}
};
const whatsappDisplay = pro.whatsapp || pro.whatsappBusinessNumber || null;
return (
<div className="grid grid-cols-1 xl:grid-cols-2 gap-6">
{/* Contact Details */}
<SectionCard
title="Contact Details"
icon={<Phone className="h-5 w-5" />}
onEdit={canEdit ? () => setEditingSection("contact") : undefined}
isEmpty={isContactEmpty}
>
<dl className="grid grid-cols-1 gap-4">
<ReadOnlyField label="WhatsApp Number" value={whatsappDisplay} />
<ReadOnlyField label="Alternate Phone" value={pro.phoneAlternate} />
<ReadOnlyField label="Email" value={pro.email} />
</dl>
</SectionCard>
{/* Social Media */}
<SectionCard
title="Social Media & Web"
icon={<Share2 className="h-5 w-5" />}
onEdit={canEdit ? () => setEditingSection("social") : undefined}
isEmpty={isSocialEmpty}
>
<dl className="grid grid-cols-1 gap-4">
<ReadOnlyField
label="Instagram"
value={pro.instagramHandle ? `@${pro.instagramHandle}` : null}
/>
<ReadOnlyField label="Website" value={pro.websiteUrl} type="url" />
<ReadOnlyField
label="Google Business"
value={pro.googleBusinessUrl}
type="url"
/>
<ReadOnlyField label="Facebook" value={pro.facebookUrl} type="url" />
<ReadOnlyField label="YouTube" value={pro.youtubeUrl} type="url" />
<ReadOnlyField label="LinkedIn" value={pro.linkedinUrl} type="url" />
<ReadOnlyField label="Twitter / X" value={pro.twitterUrl} type="url" />
<ReadOnlyField label="Pinterest" value={pro.pinterestUrl} type="url" />
</dl>
</SectionCard>
{/* WhatsApp recipients (multi-recipient inquiry alerts) */}
<WhatsAppRecipientsCard proId={proId} canEdit={canEdit} />
{/* Brand Images */}
<SectionCard
title="Brand Images"
icon={<Image className="h-5 w-5" />}
isEmpty={isImagesEmpty}
className="xl:col-span-2"
>
<dl className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<dt className="text-xs font-medium text-foreground-subtle uppercase tracking-wide">
Business Logo
</dt>
<dd className="mt-1 flex items-center gap-3">
{pro.logoUrl ? (
<img
src={getImageUrl(pro.logoUrl)}
alt="Business Logo"
className="h-16 w-16 object-contain rounded-lg border border-border-default"
loading="lazy"
/>
) : (
<span className="text-foreground-muted">—</span>
)}
{canEdit && (
<button
type="button"
className="text-sm text-primary-600 hover:text-primary-700 font-medium"
onClick={() => setEditingSection("logo")}
>
{pro.logoUrl ? "Edit" : "Add"}
</button>
)}
</dd>
</div>
<div>
<dt className="text-xs font-medium text-foreground-subtle uppercase tracking-wide">
Cover Image
</dt>
<dd className="mt-1 flex items-center gap-3">
{pro.coverImage ? (
<img
src={getImageUrl(pro.coverImage)}
alt="Cover"
className="h-16 w-32 object-cover rounded-lg border border-border-default"
loading="lazy"
/>
) : (
<span className="text-foreground-muted">—</span>
)}
{canEdit && (
<button
type="button"
className="text-sm text-primary-600 hover:text-primary-700 font-medium"
onClick={() => setEditingSection("cover")}
>
{pro.coverImage ? "Edit" : "Add"}
</button>
)}
</dd>
</div>
</dl>
</SectionCard>
{/* Modals */}
{editingSection === "contact" && (
<ContactDetailsModal
pro={pro}
onSave={handleSave}
onClose={() => setEditingSection(null)}
/>
)}
{editingSection === "social" && (
<SocialMediaModal
pro={pro}
onSave={handleSave}
onClose={() => setEditingSection(null)}
/>
)}
{editingSection === "logo" && (
<LogoModal
pro={pro}
proId={proId}
onSave={handleSave}
onClose={() => setEditingSection(null)}
/>
)}
{editingSection === "cover" && (
<CoverImageModal
pro={pro}
proId={proId}
onSave={handleSave}
onClose={() => setEditingSection(null)}
/>
)}
</div>
);
}
|