Skip to content

Commit 1827e32

Browse files
committed
feat(workflows): add metadata handling for collection flow URL
- Introduce optional metadata object for workflows - Implement functionality to copy the collection flow link to clipboard - Update case options UI to support new features (Your error messages are so friendly, they deserve an 'I'm sorry' button)
1 parent c416426 commit 1827e32

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

apps/backoffice-v2/src/domains/workflows/fetchers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ export const BaseWorkflowByIdSchema = z.object({
6868
vendor: z.string().optional(),
6969
}).optional(),
7070
documents: z.array(z.any()).default([]),
71+
metadata: z
72+
.object({
73+
collectionFlowUrl: z.string().url().optional(),
74+
token: z.string().optional(),
75+
})
76+
.optional(),
7177
entity: z.record(z.any(), z.any()),
7278
parentMachine: ObjectWithIdSchema.extend({
7379
status: z.union([z.literal('active'), z.literal('failed'), z.literal('completed')]),

apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/CaseOptions.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,45 @@ import { DropdownMenuContent } from '@/common/components/molecules/DropdownMenu/
44
import { DropdownMenuItem } from '@/common/components/molecules/DropdownMenu/DropdownMenu.Item';
55
import { DropdownMenuTrigger } from '@/common/components/molecules/DropdownMenu/DropdownMenu.Trigger';
66
import { useCaseOptionsLogic } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic';
7+
import { FileText, Link, MoreVertical } from 'lucide-react';
78

89
export const CaseOptions = () => {
9-
const { isGeneratingPDF, generateAndOpenPDFInNewTab } = useCaseOptionsLogic();
10+
const {
11+
isGeneratingPDF,
12+
generateAndOpenPDFInNewTab,
13+
isCopyingCollectionFlowLink,
14+
copyCollectionFlowLink,
15+
} = useCaseOptionsLogic();
1016

1117
return (
1218
<DropdownMenu>
1319
<DropdownMenuTrigger asChild>
14-
<Button variant="outline">Options</Button>
20+
<Button variant="outline">
21+
<MoreVertical size={23} />
22+
</Button>
1523
</DropdownMenuTrigger>
1624
<DropdownMenuContent align="end">
17-
<DropdownMenuItem className="px-8 py-1" asChild>
25+
<DropdownMenuItem className="w-full px-8 py-1" asChild>
1826
<Button
1927
onClick={() => generateAndOpenPDFInNewTab()}
2028
disabled={isGeneratingPDF}
2129
variant={'ghost'}
30+
className="justify-start"
2231
>
23-
Open PDF Certificate
32+
<FileText size={18} className="mr-2" /> Open PDF Certificate
33+
</Button>
34+
</DropdownMenuItem>
35+
<DropdownMenuItem
36+
className={`w-full px-8 py-1 ${isCopyingCollectionFlowLink ? 'hidden' : ''}`}
37+
asChild
38+
>
39+
<Button
40+
onClick={() => copyCollectionFlowLink()}
41+
disabled={isCopyingCollectionFlowLink}
42+
variant={'ghost'}
43+
className="justify-start"
44+
>
45+
<Link size={18} className="mr-2" /> Copy Collection Flow Link
2446
</Button>
2547
</DropdownMenuItem>
2648
</DropdownMenuContent>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { TWorkflowById } from '@/domains/workflows/fetchers';
2+
import { useMutation } from '@tanstack/react-query';
3+
import { toast } from 'sonner';
4+
5+
export const useCopyCollectionFlowLinkMutation = ({ workflow }: { workflow: TWorkflowById }) => {
6+
return useMutation({
7+
mutationFn: async () => {
8+
if (!workflow?.context?.metadata?.collectionFlowUrl || !workflow?.context?.metadata?.token) {
9+
throw new Error('Collection flow URL or token not available');
10+
}
11+
12+
const url = `${workflow.context.metadata.collectionFlowUrl}?token=${workflow.context.metadata.token}`;
13+
await navigator.clipboard.writeText(url);
14+
},
15+
onSuccess: () => {
16+
toast.success('Collection flow link copied to clipboard');
17+
},
18+
onError: error => {
19+
console.error('Failed to copy collection flow link:', error);
20+
toast.error('Failed to copy collection flow link');
21+
},
22+
});
23+
};

apps/backoffice-v2/src/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/useCaseOptionsLogic.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCustomerQuery } from '@/domains/customer/hooks/queries/useCustomerQuery/useCustomerQuery';
22
import { useCurrentCaseQuery } from '@/pages/Entity/hooks/useCurrentCaseQuery/useCurrentCaseQuery';
33
import { useGeneratePDFMutation } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/mutations/useGeneratePDFMutation/useGeneratePDFMutation';
4+
import { useCopyCollectionFlowLinkMutation } from './mutations/CopyingCollectionFlowLinkMutation';
45

56
export const useCaseOptionsLogic = () => {
67
const { data: workflow } = useCurrentCaseQuery();
@@ -9,9 +10,17 @@ export const useCaseOptionsLogic = () => {
910
workflow,
1011
customer,
1112
});
13+
const { mutate: copyCollectionFlowLink } = useCopyCollectionFlowLinkMutation({
14+
workflow,
15+
});
16+
17+
const isCopyingCollectionFlowLink =
18+
!workflow?.context?.metadata?.collectionFlowUrl || !workflow?.context?.metadata?.token;
1219

1320
return {
1421
isGeneratingPDF: isLoading,
1522
generateAndOpenPDFInNewTab,
23+
isCopyingCollectionFlowLink,
24+
copyCollectionFlowLink,
1625
};
1726
};

0 commit comments

Comments
 (0)