import { Modal, ModalText, useToast } from '@ocv-web/ui' import Portal from '../../../portal/portal' import { useNotificationStatus } from '../../api/notifications' import { useHistory, useLocation } from 'react-router-dom' import React from 'react' <<<<<<< HEAD import { useUser } from '../../../administration/api/users' import { useUserSelection } from '../../../core/context/UserSelectionContext' ======= import { useHistory, useParams } from 'react-router-dom' import { OCVRouteParams } from '../../../core/types' import { useNotification } from '../../api/notifications' import AWS from 'aws-sdk' import { Auth } from 'aws-amplify' >>>>>>> master export interface IIPAWSCancelModal { show: boolean showAction: () => void cancelItem: any } <<<<<<< HEAD export const IPAWSCancelModal: React.FC<IIPAWSCancelModal> = ({ show, showAction, cancelItem, }) => { const { userEmail } = useUserSelection() const { data } = useUser(userEmail) const userName = data?.Results[0]?.Name const cancelItemId = cancelItem?.SK?.split('#')[1] const history = useHistory() const location = useLocation() const [mutatePatch] = useNotificationStatus(cancelItemId) ======= async function invokeLambda(params) { Auth.currentCredentials().then(async credentials => { const lambda = new AWS.Lambda({ region: 'us-east-2', credentials: Auth.essentialCredentials(credentials), }) const lambdaParams = { FunctionName: 'arn:aws:lambda:us-east-2:730987745435:function:ipawsCancelAlert' /* required */, InvocationType: 'RequestResponse', Payload: JSON.stringify({ sender: params.sender, messageId: params.messageId, sentOn: params.sentOn, }), } try { console.log('calling lambda') const resp = await lambda.invoke(lambdaParams).promise() console.log(resp) } catch (err) { console.log(err) } }) } export const IPAWSCancelModal: React.FC<IIPAWSCancelModal> = ({ show, showAction }) => { const { id } = useParams<OCVRouteParams>() const { data } = useNotification(id) React.useEffect(() => { console.log(data?.Results[0]) }, [data]) >>>>>>> master const { dispatch } = useToast() const handleCancel = () => { console.log('cancel') invokeLambda({ sender: data.Results[0].Response.body.sender, messageId: data.Results[0].Response.body.alertId, sentOn: data.Results[0].Response.body.sentOn, }) // // add cancel api call here // const lambdaParams = { // FunctionName: // 'arn:aws:lambda:us-east-2:730987745435:function:ipawsCancelAlert' /* required */, // InvocationType: 'RequestResponse', // Payload: { // sender: data.Results[0].Response.body.sender, // messageId: data.Results[0].Response.body.alertId, // sentOn: data.Results[0].Response.body.sentOn, // }, // } // try { // console.log('calling lambda') // const resp = lambda.invoke(lambdaParams) // console.log(resp) // } catch (err) { // console.log(err) // } try { mutatePatch({ Status: 'Inactive', Title: cancelItem.Title, Description: cancelItem.Description, Type: cancelItem.Type, SentBy: { Name: userName, Email: userEmail }, Locations: cancelItem.Locations, Expires: { Hours: 0, Minutes: 0, }, SocialMedia: { Facebook: false, Twitter: false, Instagram: false, }, FeatureToOpen: '', Groups: [], LastUpdated: new Date().toLocaleString(), }) dispatch({ type: 'add', payload: { title: 'Notification Cancelled Successfully.', status: 'success', message: 'You successfully cancelled this MAXX Notification.', }, }) showAction() if (location.pathname === '/maxx/history') { setTimeout(() => { window.location.reload() }, 1000) } else { history.push('/maxx/history') setTimeout(() => { window.location.reload() }, 1000) } } catch { dispatch({ type: 'add', payload: { title: 'Failed to Cancel Notification.', status: 'error', message: 'You failed to cancel this notification.', }, }) showAction() } } return ( show && ( <Portal id="root"> <Modal buttons width="lg" buttonColor="red" show={show} onCancel={() => showAction()} onClick={() => { handleCancel() }} buttonTitle="Cancel Notification" > <ModalText icon="exclamation-triangle" iconColor="red" title="Cancel Notification" subtitle="Are you sure you want to cancel this notification? This action cannot be undone." /> </Modal> </Portal> ) ) } export default IPAWSCancelModal
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter