Skip to content

Commit

Permalink
fix: add reassignedBy and reassign reason to both status (#17418)
Browse files Browse the repository at this point in the history
* add reassignedBy and reassign reason to both status

* fix w-full issue in dialog

* fix types

---------

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
  • Loading branch information
sean-brydon and PeerRich authored Oct 31, 2024
1 parent 64551a5 commit e728ed7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 15 deletions.
44 changes: 30 additions & 14 deletions apps/web/components/dialog/ReassignDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,24 @@ export const ReassignDialog = ({ isOpenDialog, setIsOpenDialog, teamId, bookingI
},
});

const [showConfirmation, setShowConfirmation] = useState(false);
const [confirmationModal, setConfirmationModal] = useState<{
show: boolean;
membersStatus: "unavailable" | "available" | null;
}>({
show: false,
membersStatus: null,
});

const handleSubmit = (values: FormValues) => {
if (values.reassignType === "round_robin") {
roundRobinReassignMutation.mutate({ teamId, bookingId });
} else {
if (values.teamMemberId) {
const selectedMember = teamMemberOptions?.find((member) => member.value === values.teamMemberId);
if (selectedMember && selectedMember.status === "unavailable") {
setShowConfirmation(true);
} else {
roundRobinManualReassignMutation.mutate({
bookingId,
teamMemberId: values.teamMemberId,
reassignReason: values.reassignReason,
if (selectedMember) {
setConfirmationModal({
show: true,
membersStatus: selectedMember.status as "available" | "unavailable",
});
}
}
Expand Down Expand Up @@ -263,10 +266,16 @@ export const ReassignDialog = ({ isOpenDialog, setIsOpenDialog, teamId, bookingI
</DialogContent>
</Dialog>

<Dialog open={showConfirmation} onOpenChange={setShowConfirmation}>
<Dialog
open={confirmationModal?.show}
onOpenChange={(open) => setConfirmationModal({ ...confirmationModal, show: open })}>
<ConfirmationDialogContent
variety="warning"
title={t("confirm_reassign_unavailable")}
variety={confirmationModal?.membersStatus === "unavailable" ? "warning" : "success"}
title={
confirmationModal?.membersStatus === "unavailable"
? t("confirm_reassign_unavailable")
: t("confirm_reassign_available")
}
confirmBtnText={t("yes_reassign")}
cancelBtnText={t("cancel")}
onConfirm={() => {
Expand All @@ -279,14 +288,21 @@ export const ReassignDialog = ({ isOpenDialog, setIsOpenDialog, teamId, bookingI
teamMemberId,
reassignReason: form.getValues("reassignReason"),
});
setShowConfirmation(false);
setConfirmationModal({
show: false,
membersStatus: null,
});
}}>
<p className="mb-4">{t("reassign_unavailable_team_member_description")}</p>
<p className="mb-4">
{confirmationModal?.membersStatus === "unavailable"
? t("reassign_unavailable_team_member_description")
: t("reassign_available_team_member_description")}
</p>
<TextAreaField
name="reassignReason"
label={t("reassign_reason")}
onChange={(e) => form.setValue("reassignReason", e.target.value)}
required
required={confirmationModal?.membersStatus === "unavailable"}
/>
</ConfirmationDialogContent>
</Dialog>
Expand Down
2 changes: 2 additions & 0 deletions apps/web/public/static/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,9 @@
"you_dont_have_access_to_reroute_this_booking": "You don't have access to reroute this booking",
"form_response_not_found": "Form response not found",
"confirm_reassign_unavailable": "Host unavailable",
"confirm_reassign_available": "Host available",
"reassign_unavailable_team_member_description": "Are you sure you want to reassign this booking to an unavailable host?",
"reassign_available_team_member_description": "Are you sure you want to reassign this booking?",
"yes_reassign": "Yes, reassign",
"reassign_reason": "Reason for reassigning",
"reassigned_by": "Reassigned by",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ export const roundRobinManualReassignment = async ({
newUserId,
orgId,
reassignReason,
reassignedById,
}: {
bookingId: number;
newUserId: number;
orgId: number | null;
reassignReason?: string;
reassignedById: number;
}) => {
const roundRobinReassignLogger = logger.getSubLogger({
prefix: ["roundRobinManualReassign", `${bookingId}`],
Expand Down Expand Up @@ -164,6 +166,7 @@ export const roundRobinManualReassignment = async ({
title: newBookingTitle,
userPrimaryEmail: newUser.email,
reassignReason,
reassignById: reassignedById,
},
select: bookingSelect,
});
Expand Down
1 change: 1 addition & 0 deletions packages/lib/test/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const buildBooking = (
fromReschedule: null,
recurringEventId: null,
smsReminderNumber: null,
reassignById: null,
scheduledJobs: [],
metadata: null,
responses: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Booking" ADD COLUMN "reassignById" INTEGER;

-- AddForeignKey
ALTER TABLE "Booking" ADD CONSTRAINT "Booking_reassignById_fkey" FOREIGN KEY ("reassignById") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions packages/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ model User {
NotificationsSubscriptions NotificationsSubscriptions[]
referralLinkId String?
features UserFeatures[]
reassignedBookings Booking[] @relation("reassignByUser")
@@unique([email])
@@unique([email, username])
Expand Down Expand Up @@ -608,6 +609,8 @@ model Booking {
cancellationReason String?
rejectionReason String?
reassignReason String?
reassignBy User? @relation("reassignByUser", fields: [reassignById], references: [id])
reassignById Int?
dynamicEventSlugRef String?
dynamicGroupSlugRef String?
rescheduled Boolean?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const roundRobinManualReassignHandler = async ({ ctx, input }: RoundRobin
newUserId: teamMemberId,
orgId: ctx.user.organizationId,
reassignReason,
reassignedById: ctx.user.id,
});

return { success: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const ConfirmationContent = (props: PropsWithChildren<ConfirmationDialogC
)}
</div>
)}
<div>
<div className="w-full">
<DialogPrimitive.Title className="font-cal text-emphasis mt-2 text-xl">
{title}
</DialogPrimitive.Title>
Expand Down

0 comments on commit e728ed7

Please sign in to comment.