1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00
unleash.unleash/frontend/src/component/application/ApplicationUpdate/ApplicationUpdate.tsx

87 lines
3.4 KiB
TypeScript
Raw Normal View History

2022-02-09 19:09:02 +01:00
import { ChangeEvent, useState } from 'react';
import { TextField, Grid } from '@material-ui/core';
2022-02-09 16:15:07 +01:00
import { useCommonStyles } from '../../../common.styles';
import icons from '../icon-names';
import GeneralSelect from '../../common/GeneralSelect/GeneralSelect';
import useApplicationsApi from '../../../hooks/api/actions/useApplicationsApi/useApplicationsApi';
2022-02-09 19:09:02 +01:00
import useToast from '../../../hooks/useToast';
import { IApplication } from '../../../interfaces/application';
2022-02-11 15:07:58 +01:00
import useApplication from '../../../hooks/api/getters/useApplication/useApplication';
2022-02-08 16:38:08 +01:00
interface IApplicationUpdateProps {
application: IApplication;
}
export const ApplicationUpdate = ({ application }: IApplicationUpdateProps) => {
const { storeApplicationMetaData } = useApplicationsApi();
const { appName, icon, url, description } = application;
2022-02-11 15:07:58 +01:00
const { refetchApplication } = useApplication(appName);
const [localUrl, setLocalUrl] = useState(url || '');
const [localDescription, setLocalDescription] = useState(description || '');
const { setToastData, setToastApiError } = useToast();
const commonStyles = useCommonStyles();
2022-02-11 15:07:58 +01:00
const handleChange = async (
evt: ChangeEvent<{ name?: string | undefined; value: unknown }>,
field: string,
value: string
2022-02-09 19:09:02 +01:00
) => {
evt.preventDefault();
try {
2022-02-11 15:07:58 +01:00
await storeApplicationMetaData(appName, field, value);
refetchApplication();
setToastData({
type: 'success',
title: 'Updated Successfully',
text: `${field} successfully updated`,
});
2022-02-09 19:09:02 +01:00
} catch (e: any) {
setToastApiError(e.toString());
}
};
return (
<Grid container style={{ marginTop: '1rem' }}>
<Grid item sm={12} xs={12} className={commonStyles.contentSpacingY}>
<Grid item>
<GeneralSelect
name="iconSelect"
id="selectIcon"
label="Icon"
options={icons.map(v => ({ key: v, label: v }))}
value={icon || 'apps'}
onChange={e =>
handleChange(e, 'icon', e.target.value as string)
}
/>
</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 => handleChange(e, 'url', localUrl)}
/>
</Grid>
<Grid item>
<TextField
value={localDescription}
label="Description"
variant="outlined"
size="small"
rows={2}
onChange={e => setLocalDescription(e.target.value)}
onBlur={e =>
handleChange(e, 'description', localDescription)
}
/>
</Grid>
</Grid>
</Grid>
);
};