mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 06:35:42 +00:00
fix: notify the backoffice of new booking
This commit is contained in:
@@ -253,6 +253,19 @@ export class BookingLifecycleNotifierService {
|
|||||||
|
|
||||||
// ── Staff-facing (backoffice inbox) ────────────────────────────────────────
|
// ── Staff-facing (backoffice inbox) ────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A booking was created under a contract. Contract drawdowns never pass
|
||||||
|
* through submit, so this is the only point at which staff learn the booking
|
||||||
|
* exists — {@link submittedToStaff} covers the direct-booking flow instead.
|
||||||
|
*/
|
||||||
|
createdToStaff(b: Booking): void {
|
||||||
|
this.inAppStaff(
|
||||||
|
b,
|
||||||
|
'New booking created',
|
||||||
|
`Booking ${this.ref(b)} was created under a contract and has entered the pipeline.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Customer submitted a booking for review. */
|
/** Customer submitted a booking for review. */
|
||||||
submittedToStaff(b: Booking): void {
|
submittedToStaff(b: Booking): void {
|
||||||
this.inAppStaff(
|
this.inAppStaff(
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ describe('ContractBookingService — quantity-cap completion', () => {
|
|||||||
{} as never, // workflowService
|
{} as never, // workflowService
|
||||||
{} as never, // invoiceService
|
{} as never, // invoiceService
|
||||||
{} as never, // clearanceFeeService
|
{} as never, // clearanceFeeService
|
||||||
|
{ createdToStaff: jest.fn() } as never, // bookingNotifier
|
||||||
{} as never, // dataSource
|
{} as never, // dataSource
|
||||||
{} as never, // trainSchedulingService
|
{} as never, // trainSchedulingService
|
||||||
{} as never, // bookingBatchService
|
{} as never, // bookingBatchService
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ describe('ContractBookingService — drawdown consolidation gate', () => {
|
|||||||
{} as never, // workflowService
|
{} as never, // workflowService
|
||||||
invoiceService as never,
|
invoiceService as never,
|
||||||
{} as never, // clearanceFeeService
|
{} as never, // clearanceFeeService
|
||||||
|
{ createdToStaff: jest.fn() } as never, // bookingNotifier
|
||||||
{} as never, // dataSource
|
{} as never, // dataSource
|
||||||
{} as never, // trainSchedulingService
|
{} as never, // trainSchedulingService
|
||||||
{} as never, // bookingBatchService
|
{} as never, // bookingBatchService
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { BookingContainerUnit } from '../bookings/entities/booking-container-uni
|
|||||||
import { BookingsRepository } from '../bookings/bookings.repository';
|
import { BookingsRepository } from '../bookings/bookings.repository';
|
||||||
import { BookingPricingService } from '../bookings/booking-pricing.service';
|
import { BookingPricingService } from '../bookings/booking-pricing.service';
|
||||||
import { BookingTransitionService } from '../bookings/booking-transition.service';
|
import { BookingTransitionService } from '../bookings/booking-transition.service';
|
||||||
|
import { BookingLifecycleNotifierService } from '../bookings/booking-lifecycle-notifier.service';
|
||||||
import { ConsolidationService } from '../bookings/consolidation.service';
|
import { ConsolidationService } from '../bookings/consolidation.service';
|
||||||
import { PriceLineItemDto } from '../bookings/dto/generate-price-response.dto';
|
import { PriceLineItemDto } from '../bookings/dto/generate-price-response.dto';
|
||||||
import { BookingInvoiceService } from '../bookings/booking-invoice.service';
|
import { BookingInvoiceService } from '../bookings/booking-invoice.service';
|
||||||
@@ -97,6 +98,7 @@ export class ContractBookingService {
|
|||||||
private readonly workflowService: ClearanceWorkflowService,
|
private readonly workflowService: ClearanceWorkflowService,
|
||||||
private readonly invoiceService: BookingInvoiceService,
|
private readonly invoiceService: BookingInvoiceService,
|
||||||
private readonly clearanceFeeService: ClearanceFeeService,
|
private readonly clearanceFeeService: ClearanceFeeService,
|
||||||
|
private readonly bookingNotifier: BookingLifecycleNotifierService,
|
||||||
private readonly dataSource: DataSource,
|
private readonly dataSource: DataSource,
|
||||||
@Inject(forwardRef(() => TrainSchedulingService))
|
@Inject(forwardRef(() => TrainSchedulingService))
|
||||||
private readonly trainSchedulingService: TrainSchedulingService,
|
private readonly trainSchedulingService: TrainSchedulingService,
|
||||||
@@ -352,6 +354,12 @@ export class ContractBookingService {
|
|||||||
const withContainers = await this.bookingsRepository.findByIdWithFiles(
|
const withContainers = await this.bookingsRepository.findByIdWithFiles(
|
||||||
booking.id,
|
booking.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Tell staff the booking exists. Placed after the zero-price rollback (which
|
||||||
|
// hard-deletes the row) and before the consolidation gate, so it fires
|
||||||
|
// exactly once whether the booking parks for a partner or finalizes inline.
|
||||||
|
this.bookingNotifier.createdToStaff(withContainers ?? booking);
|
||||||
|
|
||||||
const intendedStatus =
|
const intendedStatus =
|
||||||
generalCustoms || generalSelfClear
|
generalCustoms || generalSelfClear
|
||||||
? 'AWAITING_DOCUMENTS'
|
? 'AWAITING_DOCUMENTS'
|
||||||
@@ -481,6 +489,7 @@ export class ContractBookingService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const result = await this.bookingsRepository.findByIdWithFiles(booking.id);
|
const result = await this.bookingsRepository.findByIdWithFiles(booking.id);
|
||||||
|
this.bookingNotifier.createdToStaff(result ?? booking);
|
||||||
return { booking: result ?? booking, warnings: [] };
|
return { booking: result ?? booking, warnings: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,7 +577,10 @@ export class ContractBookingService {
|
|||||||
await this.clearanceFeeService.issueForBooking(booking, contract);
|
await this.clearanceFeeService.issueForBooking(booking, contract);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (await this.bookingsRepository.findByIdWithFiles(booking.id)) ?? booking;
|
const created =
|
||||||
|
(await this.bookingsRepository.findByIdWithFiles(booking.id)) ?? booking;
|
||||||
|
this.bookingNotifier.createdToStaff(created);
|
||||||
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
TextInput,
|
TextInput,
|
||||||
|
Tooltip,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { AlertCircle, ArrowLeft, ArrowRight } from "lucide-react";
|
import { AlertCircle, ArrowLeft, ArrowRight, Info } from "lucide-react";
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
|
||||||
@@ -293,22 +294,28 @@ export default function CompanyProfileForm({
|
|||||||
const [contactSameAsGm, setContactSameAsGm] = useState(false);
|
const [contactSameAsGm, setContactSameAsGm] = useState(false);
|
||||||
const [poaSameAsContact, setPoaSameAsContact] = useState(false);
|
const [poaSameAsContact, setPoaSameAsContact] = useState(false);
|
||||||
|
|
||||||
// General Manager source: the eTrade-registered business owner when a TIN
|
// General Manager source. The company step's email/phone are seeded from
|
||||||
// lookup found one, otherwise the registering user's own account details.
|
// eTrade (and the account email) but stay editable, so the link reads the
|
||||||
|
// CURRENT form values rather than the frozen eTrade snapshot — an edit on the
|
||||||
|
// company step propagates here, the same way "Same as General Manager" tracks
|
||||||
|
// the general manager's live values. eTrade's owner name has no editable
|
||||||
|
// field of its own, so it falls back to the registering user's account name.
|
||||||
|
const companyEmail = watch("companyEmail");
|
||||||
|
const companyPhone = watch("companyPhone");
|
||||||
const gmSourceName = etradeOwner?.name ?? user.name?.en ?? "";
|
const gmSourceName = etradeOwner?.name ?? user.name?.en ?? "";
|
||||||
const gmSourcePhone = etradeOwner
|
const gmSourceEmail = companyEmail || user.email || "";
|
||||||
? etradeOwner.phone
|
const gmSourcePhone =
|
||||||
: toEthiopianE164(user.phoneNumber);
|
companyPhone || etradeOwner?.phone || toEthiopianE164(user.phoneNumber) || "";
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!gmSameAsOwner) return;
|
if (!gmSameAsOwner) return;
|
||||||
setValue("generalManagerName", gmSourceName, { shouldValidate: true });
|
setValue("generalManagerName", gmSourceName, { shouldValidate: true });
|
||||||
setValue("generalManagerEmail", user.email ?? "", { shouldValidate: true });
|
setValue("generalManagerEmail", gmSourceEmail, { shouldValidate: true });
|
||||||
setValue("generalManagerPhone", gmSourcePhone ?? "", {
|
setValue("generalManagerPhone", gmSourcePhone, {
|
||||||
shouldValidate: true,
|
shouldValidate: true,
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [gmSameAsOwner, gmSourceName, gmSourcePhone, user.email]);
|
}, [gmSameAsOwner, gmSourceName, gmSourceEmail, gmSourcePhone]);
|
||||||
|
|
||||||
const toggleGmSameAsOwner = (checked: boolean) => {
|
const toggleGmSameAsOwner = (checked: boolean) => {
|
||||||
setGmSameAsOwner(checked);
|
setGmSameAsOwner(checked);
|
||||||
@@ -624,7 +631,24 @@ export default function CompanyProfileForm({
|
|||||||
{...register("vatNumber")}
|
{...register("vatNumber")}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="FAN Number (16 digits)"
|
label={
|
||||||
|
<Group gap={6} align="center" wrap="nowrap">
|
||||||
|
<span>FAN Number (16 digits)</span>
|
||||||
|
<Tooltip
|
||||||
|
label="The FAN must belong to the person with power of attorney. If the company has no power of attorney, use the general manager's FAN."
|
||||||
|
multiline
|
||||||
|
w={260}
|
||||||
|
withArrow
|
||||||
|
position="top-start"
|
||||||
|
>
|
||||||
|
<Info
|
||||||
|
size={14}
|
||||||
|
color="var(--mantine-color-gray-6)"
|
||||||
|
className="cursor-help"
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
</Group>
|
||||||
|
}
|
||||||
placeholder="1234567890123456"
|
placeholder="1234567890123456"
|
||||||
maxLength={16}
|
maxLength={16}
|
||||||
error={errors.fanNumber?.message}
|
error={errors.fanNumber?.message}
|
||||||
@@ -743,8 +767,8 @@ export default function CompanyProfileForm({
|
|||||||
title="Same as business owner"
|
title="Same as business owner"
|
||||||
description={
|
description={
|
||||||
etradeOwner
|
etradeOwner
|
||||||
? "Reuse the eTrade-registered owner's name and phone (email from your account). Uncheck to enter different details."
|
? "Reuse the eTrade-registered owner's name, plus the company email and phone as you entered them. Uncheck to enter different details."
|
||||||
: "Reuse your account's name, email and phone. Uncheck to enter different details."
|
: "Reuse your account's name and the company email and phone as you entered them. Uncheck to enter different details."
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|||||||
Reference in New Issue
Block a user