/* eslint react/no-multi-comp:off */ import React, { useContext, useState } from 'react'; import { Avatar, Icon, IconButton, LinearProgress, Link, Typography, } from '@material-ui/core'; import { Link as LinkIcon } from '@material-ui/icons'; import ConditionallyRender from 'component/common/ConditionallyRender/ConditionallyRender'; import { UPDATE_APPLICATION } from 'component/providers/AccessProvider/permissions'; import { ApplicationView } from '../ApplicationView/ApplicationView'; import { ApplicationUpdate } from '../ApplicationUpdate/ApplicationUpdate'; import Dialogue from 'component/common/Dialogue'; import PageContent from 'component/common/PageContent'; import HeaderTitle from 'component/common/HeaderTitle'; import AccessContext from 'contexts/AccessContext'; import useApplicationsApi from 'hooks/api/actions/useApplicationsApi/useApplicationsApi'; import useApplication from 'hooks/api/getters/useApplication/useApplication'; import { useHistory, useParams } from 'react-router-dom'; import { useLocationSettings } from 'hooks/useLocationSettings'; import useToast from 'hooks/useToast'; import PermissionButton from 'component/common/PermissionButton/PermissionButton'; import { formatDateYMD } from 'utils/formatDate'; import { formatUnknownError } from 'utils/formatUnknownError'; import { TabNav } from 'component/common/TabNav/TabNav/TabNav'; export const ApplicationEdit = () => { const history = useHistory(); const { name } = useParams<{ name: string }>(); const { application, loading } = useApplication(name); const { appName, url, description, icon = 'apps', createdAt } = application; const { hasAccess } = useContext(AccessContext); const { deleteApplication } = useApplicationsApi(); const { locationSettings } = useLocationSettings(); const { setToastData, setToastApiError } = useToast(); const [showDialog, setShowDialog] = useState(false); const toggleModal = () => { setShowDialog(!showDialog); }; const formatDate = (v: string) => formatDateYMD(v, locationSettings.locale); const onDeleteApplication = async (evt: React.SyntheticEvent) => { evt.preventDefault(); try { await deleteApplication(appName); setToastData({ title: 'Deleted Successfully', text: 'Application deleted successfully', type: 'success', }); history.push('/applications'); } catch (error: unknown) { setToastApiError(formatUnknownError(error)); } }; const renderModal = () => ( ); const tabData = [ { label: 'Application overview', component: , }, { label: 'Edit application', component: , }, ]; if (loading) { return (

Loading...

); } else if (!application) { return

Application ({appName}) not found

; } return ( {icon || 'apps'} {appName} } actions={ <> } /> Delete } /> } >
{description || ''} Created: {formatDate(createdAt)}
{renderModal()} } />
); };