All files / src/lib/api onboarding.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 4/4
100% Lines 5/5

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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245                                                                                                                                                                                                                                                                                                                                                                                            2x             1x                         2x                         1x                               2x          
// Onboarding API client
import { request, type ApiResponse } from "./base";
 
// Types for onboarding data
export interface OnboardingProData {
	businessName: string;
	slug: string | null;
	cityId: string | null;
	businessTypeId: string | null;
	businessTypesSecondary: string[] | null;
	customerSegmentId: string | null;
	customerSegmentsSecondary: string[] | null;
	projectScaleIds: string[] | null;
	serviceCategoryIds: string[] | null;
	materialTagIds: string[] | null;
	serviceAreaIds: string[] | null;
	yearsInBusiness: number | null;
	teamSize: string | null;
	languagesSpoken: string[] | null;
	timelineCapabilities: string[] | null;
	acceptsRushOrders: boolean;
	rushOrderPremium: string | null;
	brandsWorkWith: string[] | null;
	brandsOfficialPartner: string[] | null;
	tagline: string | null;
	about: string | null;
	establishedYear: number | null;
	instagramHandle: string | null;
	facebookUrl: string | null;
	youtubeUrl: string | null;
	googleBusinessUrl: string | null;
	websiteUrl: string | null;
	linkedinUrl: string | null;
	whatsapp: string | null;
	email: string | null;
	whatsappBusinessNumber: string | null;
	addressLine1: string | null;
	addressLine2: string | null;
	addressCity: string | null;
	addressState: string | null;
	addressPincode: string | null;
	hasOwnWorkshop: boolean;
	workshopLocation: string | null;
	installationTeamSize: string | null;
	typicalTimelines: Record<string, string> | null;
	pricingTier: string | null;
	priceRangeMin: number | null;
	priceRangeMax: number | null;
	logoUrl: string | null;
	brandColorPrimary: string | null;
	brandColorSecondary: string | null;
	// Delivery fields (from profileFields)
	factoryMade: boolean | null;
	factoryType: "own" | "partner" | null;
	siteExecution: boolean | null;
	labourOnly: boolean | null;
	fullSiteExecution: boolean | null;
	materialApproach: "we_provide" | "customer_provides" | "combination" | null;
	billingModel: "sqft_rates" | "fixed_quote" | "combination" | null;
	deliveryDaysMin: number | null;
	deliveryDaysMax: number | null;
	// Business type detail fields (from profileFields)
	pricingModel: "per_sqft" | "fixed_quote" | "cost_plus" | "daily_rate" | "package_based" | null;
	minProjectValue: number | null;
	consultationFee: "free" | "paid" | "adjustable" | null;
	warrantyYears: number | null;
	hasAfterSalesService: boolean | null;
	hasShowroom: boolean | null;
	provides3DDesign: boolean | null;
}
 
export interface OnboardingStatusResponse {
	status: "not_started" | "in_progress" | "completed";
	currentStep: number;
	completedAt: string | null;
	pro: OnboardingProData;
}
 
export interface SlugCheckResponse {
	available: boolean;
	reason?: string;
	suggestions?: string[];
	slug?: string;
}
 
export interface StepSaveResponse {
	step: number;
	saved: boolean;
	pro: OnboardingProData;
}
 
export interface CompleteResponse {
	completed: boolean;
	pro: OnboardingProData;
}
 
// Step 1: Simplified Business Info (name + slug + city + business type + whatsapp + logo)
export interface Step1Data {
	businessName: string;
	slug: string;
	cityId: string;
	businessTypeId: string;
	whatsapp: string;
	logoUrl?: string;
}
 
// Step 2: Branding (skippable)
export interface Step2Data {
	tagline?: string;
	about?: string;
	logoUrl?: string;
}
 
// Step 3: Contact & Social (skippable)
export interface Step3Data {
	whatsapp?: string;
	email?: string;
	instagramHandle?: string;
	facebookUrl?: string;
	youtubeUrl?: string;
	googleBusinessUrl?: string;
	websiteUrl?: string;
	linkedinUrl?: string;
	whatsappBusinessNumber?: string;
}
 
// Step 4: Services
export interface Step4Data {
	businessTypeId: string;
	businessTypesSecondary?: string[];
	serviceCategoryIds?: string[];
	materialTagIds?: string[];
	brandsWorkWith?: string[];
	brandsOfficialPartner?: string[];
}
 
// Step 5: Customer Segments & Pricing
export interface Step5Data {
	customerSegmentId: string;
	customerSegmentsSecondary?: string[];
	priceRangeMin: number;
	priceRangeMax?: number;
	pricingModel: "per_sqft" | "fixed_quote" | "cost_plus" | "daily_rate" | "package_based";
}
 
// Step 6: Delivery Configuration
export interface Step6Data {
	factoryMade?: boolean;
	factoryType?: "own" | "partner";
	siteExecution?: boolean;
	labourOnly?: boolean;
	fullSiteExecution?: boolean;
	materialApproach?: "we_provide" | "customer_provides" | "combination";
	billingModel?: "sqft_rates" | "fixed_quote" | "combination";
	deliveryDaysMin?: number;
	deliveryDaysMax?: number | null;
	consultationFee?: "free" | "paid" | "adjustable";
	warrantyYears?: number;
	hasAfterSalesService?: boolean;
	hasShowroom?: boolean;
	provides3DDesign?: boolean;
}
 
// Step 7: First Project (skippable)
export interface Step7Data {
	projectCreated?: boolean;
}
 
export type StepData =
	| Step1Data
	| Step2Data
	| Step3Data
	| Step4Data
	| Step5Data
	| Step6Data
	| Step7Data;
 
// Maps step number to its data type for compile-time safety
export type StepDataMap = {
	1: Step1Data;
	2: Step2Data;
	3: Step3Data;
	4: Step4Data;
	5: Step5Data;
	6: Step6Data;
	7: Step7Data;
};
 
export type StepNumber = keyof StepDataMap;
 
export const onboardingApi = {
	/**
	 * Get onboarding status and pro data
	 */
	async getStatus(
		proId: string,
	): Promise<ApiResponse<OnboardingStatusResponse>> {
		return request<OnboardingStatusResponse>(
			`/api/pro/${proId}/onboarding/status`,
		);
	},
 
	/**
	 * Save step data. The generic ensures the data shape matches the step number.
	 */
	async saveStep<S extends StepNumber>(
		proId: string,
		stepNumber: S,
		data: StepDataMap[S],
	): Promise<ApiResponse<StepSaveResponse>> {
		return request<StepSaveResponse>(
			`/api/pro/${proId}/onboarding/step/${stepNumber}`,
			{
				method: "POST",
				body: data,
			},
		);
	},
 
	/**
	 * Complete onboarding
	 */
	async complete(proId: string): Promise<ApiResponse<CompleteResponse>> {
		return request<CompleteResponse>(
			`/api/pro/${proId}/onboarding/complete`,
			{
				method: "POST",
				body: {},
			},
		);
	},
 
	/**
	 * Check slug availability
	 */
	async checkSlug(
		proId: string,
		slug: string,
	): Promise<ApiResponse<SlugCheckResponse>> {
		return request<SlugCheckResponse>(
			`/api/pro/${proId}/onboarding/slug/check?slug=${encodeURIComponent(slug)}`,
		);
	},
};