feat(services): Add deposit percentage option for fixed-price services

- Add deposit_percent field back to Service model for percentage-based deposits
- Reorganize service form: variable pricing toggle at top, deposit toggle with
  amount/percent options (percent only available for fixed pricing)
- Disable price field when variable pricing is enabled
- Add backend validation: variable pricing cannot use percentage deposits
- Update frontend types and hooks to handle deposit_percent field

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
poduck
2025-12-04 13:52:51 -05:00
parent c7308ad167
commit cf91bae24f
6 changed files with 279 additions and 48 deletions

View File

@@ -26,7 +26,8 @@ export const useServices = () => {
photos: s.photos || [],
// Pricing fields
variable_pricing: s.variable_pricing ?? false,
deposit_amount: s.deposit_amount ? parseFloat(s.deposit_amount) : 0,
deposit_amount: s.deposit_amount ? parseFloat(s.deposit_amount) : null,
deposit_percent: s.deposit_percent ? parseFloat(s.deposit_percent) : null,
requires_deposit: s.requires_deposit ?? false,
requires_saved_payment_method: s.requires_saved_payment_method ?? false,
deposit_display: s.deposit_display || null,
@@ -68,7 +69,8 @@ interface ServiceInput {
description?: string;
photos?: string[];
variable_pricing?: boolean;
deposit_amount?: number; // 0 = no deposit
deposit_amount?: number | null;
deposit_percent?: number | null;
}
/**
@@ -94,6 +96,9 @@ export const useCreateService = () => {
if (serviceData.deposit_amount !== undefined) {
backendData.deposit_amount = serviceData.deposit_amount;
}
if (serviceData.deposit_percent !== undefined) {
backendData.deposit_percent = serviceData.deposit_percent;
}
const { data } = await apiClient.post('/services/', backendData);
return data;
@@ -121,6 +126,7 @@ export const useUpdateService = () => {
// Pricing fields
if (updates.variable_pricing !== undefined) backendData.variable_pricing = updates.variable_pricing;
if (updates.deposit_amount !== undefined) backendData.deposit_amount = updates.deposit_amount;
if (updates.deposit_percent !== undefined) backendData.deposit_percent = updates.deposit_percent;
const { data } = await apiClient.patch(`/services/${id}/`, backendData);
return data;