import React, { FC, useState } from 'react'; import { Box, Button, IconButton, styled } from '@mui/material'; import Input from 'component/common/Input/Input'; import { IChangeRequest } from '../../changeRequest.types'; import { Edit } from '@mui/icons-material'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi'; import { formatUnknownError } from 'utils/formatUnknownError'; import useToast from 'hooks/useToast'; const StyledBox = styled(Box)(({ theme }) => ({ display: 'flex', flexDirection: 'row', width: '100%', '& > div': { width: '100%' }, justifyContent: 'space-between', })); export const EnvironmentChangeRequestTitle: FC<{ environmentChangeRequest: IChangeRequest; }> = ({ environmentChangeRequest }) => { const [title, setTitle] = useState(environmentChangeRequest.title); const [isDisabled, setIsDisabled] = useState(true); const { updateTitle } = useChangeRequestApi(); const { setToastData, setToastApiError } = useToast(); const toggleEditState = () => { setIsDisabled(!isDisabled); }; const saveTitle = async () => { toggleEditState(); try { await updateTitle( environmentChangeRequest.project, environmentChangeRequest.id, title ); setToastData({ type: 'success', title: 'Change request title updated!', }); } catch (error: unknown) { setToastApiError(formatUnknownError(error)); } }; return ( setTitle(e.target.value)} disabled={isDisabled} /> } /> {' '} } /> ); };