Skip to content

Commit

Permalink
Merge branch 'main' into hitpay-app
Browse files Browse the repository at this point in the history
  • Loading branch information
kutsaniuk authored Dec 10, 2024
2 parents 917d85e + 9c9d7fe commit a404a5c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/web/public/static/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,7 @@
"start_date_must_be_before_end_date": "Start date must be before end date",
"start_date_must_be_in_the_future": "Start date must be in the future",
"user_not_found": "User not found",
"cannot_redirect_to_self": "Cannot redirect to self",
"out_of_office_entry_already_exists": "Out of office entry already exists",
"out_of_office_id_required": "Out of office entry id required",
"booking_redirect_infinite_not_allowed": "There is already a booking redirect from that user to you.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ export function RoutingFormResponsesTable({
});
}, [flatData, headers, isHeadersLoading]);

const statusOrder: Record<BookingStatus, number> = {
[BookingStatus.ACCEPTED]: 1,
[BookingStatus.PENDING]: 2,
[BookingStatus.AWAITING_HOST]: 3,
[BookingStatus.CANCELLED]: 4,
[BookingStatus.REJECTED]: 5,
};

const columnHelper = createColumnHelper<RoutingFormTableRow>();

const columns = useMemo(
Expand Down Expand Up @@ -358,6 +366,14 @@ export function RoutingFormResponsesTable({
<BookingStatusBadge booking={info.getValue()} />
</div>
),
sortingFn: (rowA, rowB) => {
const statusA = rowA.original.routedToBooking?.status;
const statusB = rowB.original.routedToBooking?.status;
// Default to highest number (5) + 1 for null/undefined values to sort them last
const orderA = statusA ? statusOrder[statusA] : 6;
const orderB = statusB ? statusOrder[statusB] : 6;
return orderA - orderB;
},
}),
columnHelper.accessor("routedToBooking", {
id: "bookingAt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect

let toUserId: number | null = null;

if (input.toTeamUserId === ctx.user.id) {
throw new TRPCError({ code: "BAD_REQUEST", message: "cannot_redirect_to_self" });
}

if (input.toTeamUserId) {
const user = await prisma.user.findUnique({
where: {
Expand Down Expand Up @@ -108,7 +112,7 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
},
});

if (isDuplicateOutOfOfficeEntry) {
if (isDuplicateOutOfOfficeEntry && isDuplicateOutOfOfficeEntry?.uuid !== input.uuid) {
throw new TRPCError({ code: "CONFLICT", message: "out_of_office_entry_already_exists" });
}

Expand All @@ -132,6 +136,7 @@ export const outOfOfficeCreateOrUpdate = async ({ ctx, input }: TBookingRedirect
const createdOrUpdatedOutOfOffice = await prisma.outOfOfficeEntry.upsert({
where: {
uuid: input.uuid ?? "",
userId: ctx.user.id,
},
create: {
uuid: uuidv4(),
Expand Down

0 comments on commit a404a5c

Please sign in to comment.