Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the Mark as duplicate/fraud button if the payout has already completed #1739

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions apps/web/lib/actions/update-sale-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,41 @@ import { SaleStatus } from "@prisma/client";
import { z } from "zod";
import { authActionClient } from "./safe-action";

const schema = z.object({
const updateSaleStatusSchema = z.object({
workspaceId: z.string(),
saleId: z.string(),
status: z.nativeEnum(SaleStatus),
});

export const updateSaleStatusAction = authActionClient
.schema(schema)
.schema(updateSaleStatusSchema)
.action(async ({ parsedInput, ctx }) => {
const { workspace } = ctx;
const { saleId, status } = parsedInput;

await prisma.sale.update({
const sale = await prisma.sale.findUniqueOrThrow({
where: {
id: saleId,
program: {
workspaceId: workspace.id,
},
},
});

if (sale.status === "paid") {
throw new Error("You cannot update a paid sale status.");
}

await prisma.sale.update({
where: {
id: sale.id,
},
data: {
status,
},
});

// TODO:
// Send email to the partner informing them about the sale status change

// TODO: [payouts] Send email to the partner informing them about the sale status change
// TODO: [payouts] Update associated payout based on new status (fraud, duplicate, etc.)

return {
Expand Down
8 changes: 8 additions & 0 deletions apps/web/ui/partners/sale-row-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export function SaleRowMenu({ row }: { row: Row<SaleProps> }) {
);
};

const isPaid = row.original.status === "paid";

return (
<Popover
openPopover={isOpen}
Expand Down Expand Up @@ -77,6 +79,7 @@ export function SaleRowMenu({ row }: { row: Row<SaleProps> }) {
updateStatus("duplicate");
setIsOpen(false);
}}
disabled={isPaid}
/>
<MenuItem
icon={ShieldAlert}
Expand All @@ -85,6 +88,7 @@ export function SaleRowMenu({ row }: { row: Row<SaleProps> }) {
updateStatus("fraud");
setIsOpen(false);
}}
disabled={isPaid}
/>
</>
)}
Expand All @@ -107,18 +111,22 @@ function MenuItem({
icon: IconComp,
label,
onSelect,
disabled,
}: {
icon: Icon;
label: string;
onSelect: () => void;
disabled?: boolean;
}) {
return (
<Command.Item
className={cn(
"flex cursor-pointer select-none items-center gap-2 whitespace-nowrap rounded-md p-2 text-sm text-neutral-600",
"data-[selected=true]:bg-gray-100",
disabled && "cursor-not-allowed opacity-50",
)}
onSelect={onSelect}
disabled={disabled}
>
<IconComp className="size-4 shrink-0 text-neutral-500" />
{label}
Expand Down
Loading