All files / src/lib profile-completeness.ts

100% Statements 8/8
100% Branches 10/10
100% Functions 4/4
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                      55x                                                                                       330x 55x 330x 30x 55x   55x    
import type { Pro } from "./api";
 
interface CompletionSection {
	name: string;
	weight: number;
	completed: boolean;
	href: string;
	tab?: string;
}
 
export function getProfileCompleteness(pro: Pro, projectCount: number) {
	const sections: CompletionSection[] = [
		{
			name: "Add a project",
			weight: 25,
			completed: projectCount > 0,
			href: "/projects",
		},
		{
			name: "Add business address",
			weight: 15,
			completed: !!(pro.addressLine1 && pro.addressCity && pro.addressPincode),
			href: "/profile",
			tab: "basics",
		},
		{
			name: "Set pricing & customer segment",
			weight: 15,
			completed: !!(pro.priceRangeMin && pro.customerSegmentId),
			href: "/profile",
			tab: "delivery",
		},
		{
			name: "Add services & specializations",
			weight: 15,
			completed: !!(pro.serviceCategoryIds?.length),
			href: "/profile",
			tab: "services",
		},
		{
			name: "Add tagline & about",
			weight: 15,
			completed: !!(pro.tagline && pro.about),
			href: "/profile",
			tab: "basics",
		},
		{
			name: "Add social media links",
			weight: 15,
			completed: !!(pro.instagramHandle || pro.facebookUrl || pro.websiteUrl),
			href: "/profile",
			tab: "social",
		},
	];
 
	const totalWeight = sections.reduce((sum, s) => sum + s.weight, 0);
	const completedWeight = sections
		.filter((s) => s.completed)
		.reduce((sum, s) => sum + s.weight, 0);
	const percentage = Math.round((completedWeight / totalWeight) * 100);
 
	return { sections, percentage };
}