|
1
|
import { Trash } from "@medusajs/icons" |
|
2
|
import { AdminShippingProfileResponse } from "@medusajs/types" |
|
3
|
import { Container, Heading, toast, usePrompt } from "@medusajs/ui" |
|
4
|
import { useTranslation } from "react-i18next" |
|
5
|
import { useNavigate } from "react-router-dom" |
|
6
|
import { ActionMenu } from "../../../../../components/common/action-menu" |
|
7
|
import { SectionRow } from "../../../../../components/common/section" |
|
8
|
import { useDeleteShippingProfile } from "../../../../../hooks/api/shipping-profiles" |
|
9
|
|
|
10
|
type ShippingProfileGeneralSectionProps = { |
|
11
|
profile: AdminShippingProfileResponse["shipping_profile"] |
|
12
|
} |
|
13
|
|
|
14
|
export const ShippingProfileGeneralSection = ({ |
|
15
|
profile, |
|
16
|
}: ShippingProfileGeneralSectionProps) => { |
|
17
|
const { t } = useTranslation() |
|
18
|
const prompt = usePrompt() |
|
19
|
const navigate = useNavigate() |
|
20
|
|
|
21
|
const { mutateAsync } = useDeleteShippingProfile(profile.id) |
|
22
|
|
|
23
|
const handleDelete = async () => { |
|
24
|
const res = await prompt({ |
|
25
|
title: t("shippingProfile.delete.title"), |
|
26
|
description: t("shippingProfile.delete.description", { |
|
27
|
name: profile.name, |
|
28
|
}), |
|
29
|
verificationText: profile.name, |
|
30
|
verificationInstruction: t("general.typeToConfirm"), |
|
31
|
confirmText: t("actions.delete"), |
|
32
|
cancelText: t("actions.cancel"), |
|
33
|
}) |
|
34
|
|
|
35
|
if (!res) { |
|
36
|
return |
|
37
|
} |
|
38
|
|
|
39
|
await mutateAsync(undefined, { |
|
40
|
onSuccess: () => { |
|
41
|
toast.success( |
|
42
|
t("shippingProfile.delete.successToast", { |
|
43
|
name: profile.name, |
|
44
|
}) |
|
45
|
) |
|
46
|
|
|
47
|
navigate("/settings/locations/shipping-profiles", { replace: true }) |
|
48
|
}, |
|
49
|
onError: (error) => { |
|
50
|
toast.error(error.message) |
|
51
|
}, |
|
52
|
}) |
|
53
|
} |
|
54
|
|
|
55
|
return ( |
|
56
|
<Container className="divide-y p-0"> |
|
57
|
<div className="flex items-center justify-between px-6 py-4"> |
|
58
|
<Heading>{profile.name}</Heading> |
|
59
|
<ActionMenu |
|
60
|
groups={[ |
|
61
|
{ |
|
62
|
actions: [ |
|
63
|
{ |
|
64
|
icon: <Trash />, |
|
65
|
label: t("actions.delete"), |
|
66
|
onClick: handleDelete, |
|
67
|
}, |
|
68
|
], |
|
69
|
}, |
|
70
|
]} |
|
71
|
/> |
|
72
|
</div> |
|
73
|
<SectionRow title={t("fields.type")} value={profile.type} /> |
|
74
|
</Container> |
|
75
|
) |
|
76
|
} |