mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-19 17:52:45 +02:00
* refactor: update mui packages * refactor: run mui codemods * refactor: format files after codemods * refactor: fix broken types * refactor: clean up theme * refactor: fix broken tests * refactor: replace @mui/styles with tss-react * refactor: move breakpoints into classes for tss * refactor: fix crash on missing feature description * refactor: remove void classNames * refactor: adjust styles to new defaults * refactor: remove broken rollout slider e2e test * refactor: fix duplicate e2e testid * refactor: update makeStyles after rebase * refactor: add missing snapshot after rebase * refactor: fix TableCellSortable focus styles * refactor: use 1.4 as the default line-height * refactor: hide webkit search field icons * refactor: fix select box label * refactor: make AutocompleteBox smaller * refactor: make heading smaller * refactor: fix toast close icon color * refactor: update snapshots * refactor: add missing test event awaits * refactor: fix default button line-height
86 lines
3.3 KiB
TypeScript
86 lines
3.3 KiB
TypeScript
import { ChangeEvent, useState } from 'react';
|
|
import { Grid, TextField } from '@mui/material';
|
|
import { useThemeStyles } from 'themes/themeStyles';
|
|
import icons from 'component/application/iconNames';
|
|
import GeneralSelect from 'component/common/GeneralSelect/GeneralSelect';
|
|
import useApplicationsApi from 'hooks/api/actions/useApplicationsApi/useApplicationsApi';
|
|
import useToast from 'hooks/useToast';
|
|
import { IApplication } from 'interfaces/application';
|
|
import useApplication from 'hooks/api/getters/useApplication/useApplication';
|
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
|
|
|
interface IApplicationUpdateProps {
|
|
application: IApplication;
|
|
}
|
|
|
|
export const ApplicationUpdate = ({ application }: IApplicationUpdateProps) => {
|
|
const { storeApplicationMetaData } = useApplicationsApi();
|
|
const { appName, icon, url, description } = application;
|
|
const { refetchApplication } = useApplication(appName);
|
|
const [localUrl, setLocalUrl] = useState(url || '');
|
|
const [localDescription, setLocalDescription] = useState(description || '');
|
|
const { setToastData, setToastApiError } = useToast();
|
|
const { classes: themeStyles } = useThemeStyles();
|
|
|
|
const onChange = async (
|
|
field: string,
|
|
value: string,
|
|
event?: ChangeEvent
|
|
) => {
|
|
event?.preventDefault();
|
|
try {
|
|
await storeApplicationMetaData(appName, field, value);
|
|
refetchApplication();
|
|
setToastData({
|
|
type: 'success',
|
|
title: 'Updated Successfully',
|
|
text: `${field} successfully updated`,
|
|
});
|
|
} catch (error: unknown) {
|
|
setToastApiError(formatUnknownError(error));
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Grid container style={{ marginTop: '1rem' }}>
|
|
<Grid item sm={12} xs={12} className={themeStyles.contentSpacingY}>
|
|
<Grid item>
|
|
<GeneralSelect
|
|
name="iconSelect"
|
|
id="selectIcon"
|
|
label="Icon"
|
|
options={icons.map(v => ({ key: v, label: v }))}
|
|
value={icon || 'apps'}
|
|
onChange={key => onChange('icon', key)}
|
|
/>
|
|
</Grid>
|
|
<Grid item>
|
|
<TextField
|
|
value={localUrl}
|
|
onChange={e => setLocalUrl(e.target.value)}
|
|
label="Application URL"
|
|
placeholder="https://example.com"
|
|
type="url"
|
|
variant="outlined"
|
|
size="small"
|
|
onBlur={e => onChange('url', localUrl, e)}
|
|
/>
|
|
</Grid>
|
|
<Grid item>
|
|
<TextField
|
|
value={localDescription}
|
|
label="Description"
|
|
variant="outlined"
|
|
size="small"
|
|
rows={2}
|
|
onChange={e => setLocalDescription(e.target.value)}
|
|
onBlur={e =>
|
|
onChange('description', localDescription, e)
|
|
}
|
|
/>
|
|
</Grid>
|
|
</Grid>
|
|
</Grid>
|
|
);
|
|
};
|