Skip to content

Commit

Permalink
fix: delete empty settings to correctly use default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ReidyT committed Dec 8, 2023
1 parent 399c4fa commit 0fd4a28
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/common/settings/SetText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SetText: FC<Prop> = ({
const [resourceText, setResourceText] = useState(
DEFAULT_TEXT_RESOURCE_SETTING.text,
);
const { patchAppSetting, postAppSetting, appSettingArray } =
const { patchAppSetting, postAppSetting, deleteAppSetting, appSettingArray } =
useAppSettingContext();

// This state is used to avoid to erase changes if another setting is saved.
Expand All @@ -51,10 +51,15 @@ const SetText: FC<Prop> = ({

const handleClickSaveText = (): void => {
if (textResourceSetting) {
patchAppSetting({
const payloadAppSetting = {
data: { text: resourceText },
id: textResourceSetting.id,
});
};
if (resourceText) {
patchAppSetting(payloadAppSetting);
} else {
deleteAppSetting(payloadAppSetting);
}
} else {
postAppSetting({ data: { text: resourceText }, name: resourceKey });
}
Expand Down

0 comments on commit 0fd4a28

Please sign in to comment.