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

88 lines
3.5 KiB
TypeScript
Raw Normal View History

2022-02-09 19:09:02 +01:00
import { ChangeEvent, useState } from 'react';
refactor: fix misc TS errors (#729) * refactor: update test deps * refactor: remove unused ts-expect-error annotations * refactor: add missing arg and return types * refactor: the loading prop is optional * refactor: add missing arg and return types * reafactor: fix value arg type * refactor: fix missing array type * refactor: the parameters field is an array * refactor: use undefined instead of null in state * refactor: add missing params type * refactor: add missing children prop * refactor: add missing array type * refactor: add missing React imports * refactor: use correct IProjectEnvironment type * refactor: type errors as unknown * refactor: the index prop is required * refactor: fix date prop type * refactor: fix tooltip placement prop type * refactor: fix environments state type * refactor: add missing arg types * refactor: add guard for undefined field * refactor: fix ChangePassword prop types * refactor: fix MUI import paths * refactor: add missing arg type * refactor: fix showDialog prop type * refactor: remove unused openUpdateDialog prop * refactor: add missing non-null assertion * refactor: remove unused types prop * refactor: stricten API error handler types * refactor: add missing undefined check * refactor: add missing IProject id field * refactor: fix ConditionallyRender condition prop types * refactor: remove unused args * refactor: add AddVariant prop types * refactor: add types to UIContext * refactor: fix event arg type * refactor: add missing default impressionData field * refactor: fix handleDeleteEnvironment prop args * refactor: fix IFeatureMetrics field requirements * refactor: add missing element types to ConditionallyRender * refactor: remove unused ProjectAccess projectId prop * refactor: add missing undefined check * refactor: fix getCreateTogglePath arg type * refactor: add missing IStrategyPayload import * refactor: remove unused user arg * refactor: add missing event arg type * refactor: add missing style object types * refactor: improve userApiErrors prop type * refactor: the Dialogue onClose prop is optional * refactor: fix the AddonEvents setEventValue prop type
2022-02-25 10:55:39 +01:00
import { Grid, TextField } from '@material-ui/core';
2022-02-09 16:15:07 +01:00
import { useCommonStyles } from '../../../common.styles';
import icons from 'component/application/iconNames';
2022-02-09 16:15:07 +01:00
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';
import { formatUnknownError } from 'utils/formatUnknownError';
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`,
});
refactor: fix misc TS errors (#729) * refactor: update test deps * refactor: remove unused ts-expect-error annotations * refactor: add missing arg and return types * refactor: the loading prop is optional * refactor: add missing arg and return types * reafactor: fix value arg type * refactor: fix missing array type * refactor: the parameters field is an array * refactor: use undefined instead of null in state * refactor: add missing params type * refactor: add missing children prop * refactor: add missing array type * refactor: add missing React imports * refactor: use correct IProjectEnvironment type * refactor: type errors as unknown * refactor: the index prop is required * refactor: fix date prop type * refactor: fix tooltip placement prop type * refactor: fix environments state type * refactor: add missing arg types * refactor: add guard for undefined field * refactor: fix ChangePassword prop types * refactor: fix MUI import paths * refactor: add missing arg type * refactor: fix showDialog prop type * refactor: remove unused openUpdateDialog prop * refactor: add missing non-null assertion * refactor: remove unused types prop * refactor: stricten API error handler types * refactor: add missing undefined check * refactor: add missing IProject id field * refactor: fix ConditionallyRender condition prop types * refactor: remove unused args * refactor: add AddVariant prop types * refactor: add types to UIContext * refactor: fix event arg type * refactor: add missing default impressionData field * refactor: fix handleDeleteEnvironment prop args * refactor: fix IFeatureMetrics field requirements * refactor: add missing element types to ConditionallyRender * refactor: remove unused ProjectAccess projectId prop * refactor: add missing undefined check * refactor: fix getCreateTogglePath arg type * refactor: add missing IStrategyPayload import * refactor: remove unused user arg * refactor: add missing event arg type * refactor: add missing style object types * refactor: improve userApiErrors prop type * refactor: the Dialogue onClose prop is optional * refactor: fix the AddonEvents setEventValue prop type
2022-02-25 10:55:39 +01:00
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
2022-02-09 19:09:02 +01:00
}
};
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>
);
};