All files / src/components/admin/blogs BlogProSelector.tsx

100% Statements 11/11
100% Branches 6/6
87.5% Functions 7/8
100% Lines 11/11

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                                                1x             1x               4x                                     14x   14x             14x                               2x                                         9x                                     1x               36x               1x                          
import { useState } from "react";
import { X } from "lucide-react";
import { Button } from "../../ui/button";
import type { Pro } from "../../../lib/api/pro";
import type { AttributionType, ApprovalStatus } from "../../../lib/api/blogs";
import { cn } from "../../../lib/utils";
 
interface SelectedPro {
	pro: Pro;
	attributionType: AttributionType;
	approvalStatus?: ApprovalStatus;
}
 
interface BlogProSelectorProps {
	selectedPros: SelectedPro[];
	onAdd: (pro: Pro, attributionType: AttributionType) => void;
	onRemove: (proId: string) => void;
	onUpdateAttributionType: (
		proId: string,
		attributionType: AttributionType,
	) => void;
	className?: string;
}
 
const approvalBadgeStyles: Record<ApprovalStatus, string> = {
	approved: "bg-success-light text-success",
	pending: "bg-warning-light text-warning",
	rewrite_requested: "bg-warning-light text-warning",
	declined: "bg-error-light text-error",
};
 
const approvalBadgeLabels: Record<ApprovalStatus, string> = {
	approved: "Approved",
	pending: "Pending",
	rewrite_requested: "Rewrite Requested",
	declined: "Declined",
};
 
function ApprovalBadge({ status }: { status: ApprovalStatus }) {
	return (
		<span
			className={cn(
				"inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",
				approvalBadgeStyles[status],
			)}
		>
			{approvalBadgeLabels[status]}
		</span>
	);
}
 
export function BlogProSelector({
	selectedPros,
	onAdd: _onAdd,
	onRemove,
	onUpdateAttributionType,
	className,
}: BlogProSelectorProps) {
	const [searchQuery, setSearchQuery] = useState("");
 
	const attributionTypes: Array<{ value: AttributionType; label: string }> = [
		{ value: "project_feature", label: "Project Feature" },
		{ value: "expert_quote", label: "Expert Quote" },
		{ value: "roundup", label: "Roundup Inclusion" },
		{ value: "idea_contributor", label: "Idea Contributor" },
	];
 
	return (
		<div className={cn("space-y-4", className)}>
			<div>
				<label
					htmlFor="featured-pros-search"
					className="block text-sm font-medium mb-2"
				>
					Featured Pros
				</label>
 
				{/* Search Pros */}
				<div className="flex gap-2 mb-4">
					<input
						id="featured-pros-search"
						type="text"
						value={searchQuery}
						onChange={(e) => setSearchQuery(e.target.value)}
						placeholder="Search pros..."
						className="flex h-10 flex-1 rounded-md border border-border-default bg-background-elevated px-3 py-2 text-sm"
					/>
					<Button
						type="button"
						onClick={() => {}}
						disabled={!searchQuery}
					>
						Search
					</Button>
				</div>
 
				{/* Selected Pros List */}
				<div className="space-y-3">
					{selectedPros.length === 0 ? (
						<p className="text-sm text-foreground-subtle text-center py-4">
							No pros added yet. Search to add pros.
						</p>
					) : (
						selectedPros.map(({ pro, attributionType, approvalStatus }) => (
							<div
								key={pro.id}
								className="flex items-start gap-3 p-3 border border-border-default rounded-lg bg-background-elevated"
							>
								<div className="flex-1">
									<div className="flex items-center gap-2">
										<p className="font-medium text-sm">{pro.businessName}</p>
										{approvalStatus && (
											<ApprovalBadge status={approvalStatus} />
										)}
									</div>
									<p className="text-xs text-foreground-subtle">
										{pro.primaryLocality?.city || "No location"}
									</p>
								</div>
								<div>
									<select
										value={attributionType}
										onChange={(e) =>
											onUpdateAttributionType(
												pro.id,
												e.target.value as AttributionType,
											)
										}
										className="h-8 rounded-md border border-border-default bg-background-elevated px-2 text-xs focus:outline-none focus:ring-2 focus:ring-primary-500/40 focus:border-primary-500"
									>
										{attributionTypes.map((type) => (
											<option key={type.value} value={type.value}>
												{type.label}
											</option>
										))}
									</select>
								</div>
								<button
									type="button"
									onClick={() => onRemove(pro.id)}
									className="text-foreground-subtle hover:text-error"
								>
									<X className="h-4 w-4" />
								</button>
							</div>
						))
					)}
				</div>
			</div>
		</div>
	);
}