Skip to content

Commit

Permalink
delete color settings without value (#533)
Browse files Browse the repository at this point in the history
* delete color settings without value

Signed-off-by: Tomás Castillo <[email protected]>

* allow to delete color settings from marketing settings

Signed-off-by: Tomás Castillo <[email protected]>

* reject new settings without hex color value

Signed-off-by: Tomás Castillo <[email protected]>

* Refactor hex color validation on marketing action

Signed-off-by: Tomás Castillo <[email protected]>

---------

Signed-off-by: Tomás Castillo <[email protected]>
  • Loading branch information
tomrndom authored Nov 18, 2024
1 parent ac8ed8f commit 45bedc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/actions/marketing-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import {
putRequest
} from "openstack-uicore-foundation/lib/utils/actions";
import Swal from "sweetalert2";
import { getAccessTokenSafely } from "../utils/methods";
import { getAccessTokenSafely, isHexColorSetting } from "../utils/methods";
import {
DEFAULT_PER_PAGE,
ERROR_CODE_412,
HUNDRED_PER_PAGE,
MARKETING_SETTING_TYPE_FILE,
MARKETING_SETTING_TYPE_HEX_COLOR
MARKETING_SETTING_TYPE_FILE
} from "../utils/constants";

export const REQUEST_SETTINGS = "REQUEST_SETTINGS";
Expand Down Expand Up @@ -211,9 +210,14 @@ export const saveMarketingSetting =
async (dispatch, getState) => {
if (entity.type === MARKETING_SETTING_TYPE_FILE && !file)
return Promise.resolve();
// TODO: review to save hex color settings with empty values
if (entity.type === MARKETING_SETTING_TYPE_HEX_COLOR && !entity.value)
return Promise.resolve();

// Helper function to check if the entity is a hex color setting
if (isHexColorSetting(entity)) {
// If entity is new and has no value, dont save it
if (!entity.id && !entity.value) return Promise.resolve();
// if entity exists and has no value, delete it
if (entity.id && !entity.value) return dispatch(deleteSetting(entity.id));
}

const { currentSummitState } = getState();
const accessToken = await getAccessTokenSafely();
Expand Down
6 changes: 5 additions & 1 deletion src/utils/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
MILLISECONDS_TO_SECONDS,
ONE_MINUTE,
INT_BASE,
OR_FILTER
OR_FILTER,
MARKETING_SETTING_TYPE_HEX_COLOR
} from "./constants";

const DAY_IN_SECONDS = 86400; // 86400 seconds per day
Expand Down Expand Up @@ -428,3 +429,6 @@ export const handleDDLSortByLabel = (ddlArray) =>

export const range = (start, stop, step) =>
Array.from({ length: (stop - start) / step + 1 }, (_, i) => start + i * step);

export const isHexColorSetting = (entity) =>
entity.type === MARKETING_SETTING_TYPE_HEX_COLOR;

0 comments on commit 45bedc2

Please sign in to comment.