/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: MIT-0 */ import { FunctionComponent, useCallback, useState } from 'react' import { Button, Column, ColumnLayout, Inline, Stack, Text, DeleteConfirmationDialog, Container, KeyValuePair, } from 'aws-northstar' import { useHistory, useParams } from 'react-router-dom' import NotFound from '../../../components/NotFound' import { useCustomerLocationContext } from '../../../contexts/CustomerLocationContext' import { appvars } from '../../../config' import { dayjsutc } from '../../../utils/dayjs' import MapComponent from '../../../components/MapComponent' export const Details: FunctionComponent = () => { const history = useHistory() const { customerLocationId } = useParams<{ customerLocationId: string }>() const [{ items: customerLocationItems }, { deleteItem }] = useCustomerLocationContext() const currentItem = customerLocationItems.find((x) => x.Id === customerLocationId) const [showDeleteModal, setShowDeleteModal] = useState(false) const onDeleteClick = useCallback(async () => { setShowDeleteModal(true) }, []) const onEditClick = useCallback(() => { if (currentItem == null) { throw new Error('CustomerLocationData is null') } history.push(`/${appvars.URL.CUSTOMER_LOCATION}/${currentItem.Id}/edit`) }, [currentItem, history]) const proceedWithDelete = useCallback(async () => { if (currentItem == null) { throw new Error('CustomerLocationData is null') } await deleteItem(currentItem.Id) history.push(`/${appvars.URL.CUSTOMER_LOCATION}`) }, [deleteItem, history, currentItem]) if (currentItem == null) { return } const actionGroup = ( ) const pins = [ { name: currentItem.deliveryName, latitude: currentItem.latitude, longitude: currentItem.longitude, }, ] const mapProps = { zoom: 11, width: 1000, height: 750, } return ( <> setShowDeleteModal(false)} onDeleteClicked={proceedWithDelete} > <> Are you sure you want to delete {currentItem.deliveryCode}?
) }