mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 03:29:37 +02:00
Fixed bug where user could create empty app or bookmark which was causing page to go blank
This commit is contained in:
parent
668edb03d3
commit
0b3eb2e87f
5 changed files with 29 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
### v2.3.0 (TBA)
|
### v2.3.0 (TBA)
|
||||||
- Added custom theme editor ([#246](https://github.com/pawelmalak/flame/issues/246))
|
- Added custom theme editor ([#246](https://github.com/pawelmalak/flame/issues/246))
|
||||||
|
- Fixed bug where user could create empty app or bookmark which was causing page to go blank ([#332](https://github.com/pawelmalak/flame/issues/332))
|
||||||
|
|
||||||
### v2.2.2 (2022-03-21)
|
### v2.2.2 (2022-03-21)
|
||||||
- Added option to get user location directly from the app ([#287](https://github.com/pawelmalak/flame/issues/287))
|
- Added option to get user location directly from the app ([#287](https://github.com/pawelmalak/flame/issues/287))
|
||||||
|
|
|
@ -18,10 +18,8 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
|
||||||
const { appInUpdate } = useSelector((state: State) => state.apps);
|
const { appInUpdate } = useSelector((state: State) => state.apps);
|
||||||
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { addApp, updateApp, setEditApp } = bindActionCreators(
|
const { addApp, updateApp, setEditApp, createNotification } =
|
||||||
actionCreators,
|
bindActionCreators(actionCreators, dispatch);
|
||||||
dispatch
|
|
||||||
);
|
|
||||||
|
|
||||||
const [useCustomIcon, toggleUseCustomIcon] = useState<boolean>(false);
|
const [useCustomIcon, toggleUseCustomIcon] = useState<boolean>(false);
|
||||||
const [customIcon, setCustomIcon] = useState<File | null>(null);
|
const [customIcon, setCustomIcon] = useState<File | null>(null);
|
||||||
|
@ -58,6 +56,17 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
|
||||||
const formSubmitHandler = (e: SyntheticEvent<HTMLFormElement>): void => {
|
const formSubmitHandler = (e: SyntheticEvent<HTMLFormElement>): void => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
for (let field of ['name', 'url', 'icon'] as const) {
|
||||||
|
if (/^ +$/.test(formData[field])) {
|
||||||
|
createNotification({
|
||||||
|
title: 'Error',
|
||||||
|
message: `Field cannot be empty: ${field}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const createFormData = (): FormData => {
|
const createFormData = (): FormData => {
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,17 @@ export const BookmarksForm = ({
|
||||||
const formSubmitHandler = (e: FormEvent): void => {
|
const formSubmitHandler = (e: FormEvent): void => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
for (let field of ['name', 'url', 'icon'] as const) {
|
||||||
|
if (/^ +$/.test(formData[field])) {
|
||||||
|
createNotification({
|
||||||
|
title: 'Error',
|
||||||
|
message: `Field cannot be empty: ${field}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const createFormData = (): FormData => {
|
const createFormData = (): FormData => {
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
if (customIcon) {
|
if (customIcon) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ export const ThemeCreator = ({ modalHandler }: Props): JSX.Element => {
|
||||||
if (!themeInEdit) {
|
if (!themeInEdit) {
|
||||||
addTheme(formData);
|
addTheme(formData);
|
||||||
} else {
|
} else {
|
||||||
updateTheme(formData);
|
updateTheme(formData, themeInEdit.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// close modal
|
// close modal
|
||||||
|
|
|
@ -109,10 +109,11 @@ export const editTheme =
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateTheme =
|
export const updateTheme =
|
||||||
(theme: Theme) => async (dispatch: Dispatch<UpdateThemeAction>) => {
|
(theme: Theme, originalName: string) =>
|
||||||
|
async (dispatch: Dispatch<UpdateThemeAction>) => {
|
||||||
try {
|
try {
|
||||||
const res = await axios.put<ApiResponse<Theme[]>>(
|
const res = await axios.put<ApiResponse<Theme[]>>(
|
||||||
`/api/themes/${theme.name}`,
|
`/api/themes/${originalName}`,
|
||||||
theme,
|
theme,
|
||||||
{ headers: applyAuth() }
|
{ headers: applyAuth() }
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue