import { useEffect, useState } from "react" import { PublishableApiKey } from "@medusajs/medusa" import { useTranslation } from "react-i18next" import Button from "../../../components/fundamentals/button" import InputField from "../../../components/molecules/input" import SideModal from "../../../components/molecules/modal/side-modal" import CrossIcon from "../../../components/fundamentals/icons/cross-icon" import { useAdminUpdatePublishableApiKey } from "medusa-react" import useNotification from "../../../hooks/use-notification" type DetailsModalProps = { close: () => void selectedKey?: PublishableApiKey } /** * Publishable Key details container. */ function DetailsModal(props: DetailsModalProps) { const { close, selectedKey } = props const notification = useNotification() const { t } = useTranslation() const [name, setName] = useState(selectedKey?.title) const { mutateAsync: updateKey } = useAdminUpdatePublishableApiKey( selectedKey?.id as string ) useEffect(() => { if (selectedKey) { setName(selectedKey.title) } }, [selectedKey]) const onSave = async () => { try { await updateKey({ title: name }) close() notification( t("modals-success", "Success"), t("modals-updated-the-api-key", "Updated the API key"), "success" ) } catch (e) { notification( t("modals-error", "Error"), t( "modals-failed-to-update-the-api-key", "Failed to update the API key" ), "error" ) } } return (
{/* === HEADER === */}

{t("modals-edit-api-key-details", "Edit API key details")}

{/* === DIVIDER === */}
{/* === BODY === */}
setName(value)} />
{/* === DIVIDER === */}
{/* === FOOTER === */}
) } export default DetailsModal