UNPKG

react-garden

Version:

React + TypeScript + ThreeJS app using Material UI on NextJS, Apollo Client, GraphQL + WordPress REST APIs, for ThreeD web development.. a part of the threed.ai code family.

76 lines (69 loc) 2.31 kB
// ** React Imports import { useState, useEffect } from 'react' // ** Next Import import Link from 'next/link' // ** MUI Imports import Grid from '@mui/material/Grid' import Alert from '@mui/material/Alert' // ** Third Party Components import axios from 'axios' // ** Demo Components Imports import AddPaymentDrawer from '~/views/apps/invoice/shared-drawer/AddPaymentDrawer' import SendInvoiceDrawer from '~/views/apps/invoice/shared-drawer/SendInvoiceDrawer' import EditCard from './EditCard' import EditActions from './EditActions' const InvoiceEdit = ({ id }) => { // ** State const [error, setError] = useState(false) const [data, setData] = useState(null) const [addPaymentOpen, setAddPaymentOpen] = useState(false) const [sendInvoiceOpen, setSendInvoiceOpen] = useState(false) const toggleSendInvoiceDrawer = () => setSendInvoiceOpen(!sendInvoiceOpen) const toggleAddPaymentDrawer = () => setAddPaymentOpen(!addPaymentOpen) useEffect(() => { axios .get('/apps/invoice/single-invoice', { params: { id } }) .then(res => { setData(res.data) setError(false) }) .catch(() => { setData(null) setError(true) }) }, [id]) if (data) { return ( <> <Grid container spacing={6}> <Grid item xl={9} md={8} xs={12}> <EditCard data={data} /> </Grid> <Grid item xl={3} md={4} xs={12}> <EditActions id={id} toggleSendInvoiceDrawer={toggleSendInvoiceDrawer} toggleAddPaymentDrawer={toggleAddPaymentDrawer} /> </Grid> </Grid> <SendInvoiceDrawer open={sendInvoiceOpen} toggle={toggleSendInvoiceDrawer} /> <AddPaymentDrawer open={addPaymentOpen} toggle={toggleAddPaymentDrawer} /> </> ) } else if (error) { return ( <Grid container spacing={6}> <Grid item xs={12}> <Alert severity='error'> Invoice with the id: {id} does not exist. Please check the list of invoices:{' '} <Link href='/apps/invoice/list'>Invoice List</Link> </Alert> </Grid> </Grid> ) } else { return null } } export default InvoiceEdit