/* eslint react/no-multi-comp:off */ import React, { useContext, useState } from 'react'; import { Avatar, Icon, IconButton, LinearProgress, Link, Typography, } from '@mui/material'; import { Link as LinkIcon } from '@mui/icons-material'; 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 { TabNav } from 'component/common/TabNav/TabNav/TabNav'; import { Dialogue } from 'component/common/Dialogue/Dialogue'; import { PageContent } from 'component/common/PageContent/PageContent'; import { PageHeader } from 'component/common/PageHeader/PageHeader'; import AccessContext from 'contexts/AccessContext'; import useApplicationsApi from 'hooks/api/actions/useApplicationsApi/useApplicationsApi'; import useApplication from 'hooks/api/getters/useApplication/useApplication'; import { useNavigate } 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 { useRequiredPathParam } from 'hooks/useRequiredPathParam'; export const ApplicationEdit = () => { const navigate = useNavigate(); const name = useRequiredPathParam('name'); 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', }); navigate('/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} } title={appName} actions={ <> } /> Delete } /> } >
{description || ''} Created: {formatDate(createdAt)}
{renderModal()} } />
); };