Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confirmation message when defence is configured #165

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions frontend/src/components/DefenceBox/DefenceBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,22 @@ function DefenceBox({
defenceId: string,
config: DefenceConfig[]
) => {
configureDefence(defenceId, config).then(() => {
// update state
const newDefences = defenceDetails.map((defence) => {
if (defence.id === defenceId) {
defence.config = config;
const configSuccess = configureDefence(defenceId, config).then(
(success) => {
if (success) {
// update state
const newDefences = defenceDetails.map((defence) => {
if (defence.id === defenceId) {
defence.config = config;
}
return defence;
});
setDefenceDetails(newDefences);
}
return defence;
});
setDefenceDetails(newDefences);
});
return success;
}
);
return configSuccess;
};

return (
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/components/DefenceBox/DefenceMechanism.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
margin-top: 4px;
}

.defence-mechanism-config-validated {
margin-top: 10px;
margin-bottom: 10px;
}

.validation-text {
font-size: 14px;
font-weight: 600;
}

@keyframes flash-red-active {
0% {
background-color: #eef;
Expand Down
30 changes: 27 additions & 3 deletions frontend/src/components/DefenceBox/DefenceMechanism.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DefenceConfig, DefenceInfo } from "../../models/defence";
import "./DefenceMechanism.css";
import "../StrategyBox/StrategyMechanism.css";
import DefenceConfiguration from "./DefenceConfiguration";
const { TiTick, TiTimes } = require("react-icons/ti");

function DefenceMechanism({
defenceDetail,
Expand All @@ -13,21 +14,31 @@ function DefenceMechanism({
defenceDetail: DefenceInfo;
setDefenceActive: (defenceId: string) => void;
setDefenceInactive: (defenceId: string) => void;
setDefenceConfiguration: (defenceId: string, config: DefenceConfig[]) => void;
setDefenceConfiguration: (
defenceId: string,
config: DefenceConfig[]
) => Promise<boolean>;
}) {
const [isInfoBoxVisible, setIsInfoBoxVisible] = useState<boolean>(false);
const [isConfigured, setIsConfigured] = useState<boolean>(false);
const [configValidated, setConfigValidated] = useState<boolean>(true);

const ANIMATION_FLASH_TIME_SECONDS = 1;
const ANIMATION_FLASH_REPEAT = 3;

const setConfigurationValue = (configId: string, value: string) => {
const setConfigurationValue = async (configId: string, value: string) => {
const newConfiguration = defenceDetail.config.map((config) => {
if (config.id === configId) {
config.value = value;
}
return config;
});
setDefenceConfiguration(defenceDetail.id, newConfiguration);
setDefenceConfiguration(defenceDetail.id, newConfiguration).then(
(configured) => {
setIsConfigured(true);
setConfigValidated(configured);
}
);
};

return (
Expand Down Expand Up @@ -90,6 +101,19 @@ function DefenceMechanism({
})}
</div>
) : null}
{isConfigured ? (
<div className="defence-mechanism-config-validated">
{configValidated ? (
<p className="validation-text">
<TiTick /> defence successfully configured
</p>
) : (
<p className="validation-text">
<TiTimes /> invalid input - configuration failed
</p>
)}
</div>
) : null}
</div>
) : null}
</div>
Expand Down