2021-05-05 19:51:19 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
|
|
|
import { useState } from "react";
|
|
|
|
|
2021-05-10 04:38:01 +03:00
|
|
|
import { ButtonPrimaryFull, ButtonSecondaryFull, ButtonWarningFull } from "~/components/system/components/Buttons.js";
|
2021-05-05 19:51:19 +03:00
|
|
|
import { Input } from "~/components/system/components/Input.js";
|
2021-05-10 04:38:01 +03:00
|
|
|
import { Boundary } from "~/components/system/components/fragments/Boundary.js";
|
2021-05-05 19:51:19 +03:00
|
|
|
|
|
|
|
const STYLES_TRANSPARENT_BG = css `
|
2021-05-06 17:51:09 +03:00
|
|
|
background-color: ${Constants.system.bgBlurGrayBlack};
|
2021-05-05 19:51:19 +03:00
|
|
|
width: 100%;
|
|
|
|
height: 100vh;
|
|
|
|
position: fixed;
|
|
|
|
left: 0;
|
|
|
|
top: 0;
|
|
|
|
z-index: 999999;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_MAIN_MODAL = css `
|
2021-05-10 04:38:01 +03:00
|
|
|
background-color: ${Constants.system.white};
|
2021-05-05 19:51:19 +03:00
|
|
|
width: 380px;
|
|
|
|
height: auto;
|
|
|
|
position: fixed;
|
|
|
|
left: 50%;
|
|
|
|
top: 50%;
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
border-radius: 8px;
|
|
|
|
padding: 24px;
|
|
|
|
text-align: left;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_HEADER = css `
|
2021-05-06 17:51:09 +03:00
|
|
|
color: ${Constants.system.black};
|
|
|
|
font-size: ${Constants.typescale.lvl1};
|
|
|
|
font-family: ${Constants.font.semiBold};
|
2021-05-05 19:51:19 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_SUB_HEADER = css `
|
2021-05-06 17:51:09 +03:00
|
|
|
color: ${Constants.system.textGray};
|
|
|
|
font-size: ${Constants.typescale.lvl0};
|
|
|
|
font-family: ${Constants.font.text};
|
2021-05-10 04:38:01 +03:00
|
|
|
margin-top: 16px;
|
2021-05-05 19:51:19 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_INPUT_HEADER = css `
|
2021-05-06 17:51:09 +03:00
|
|
|
color: ${Constants.system.black};
|
|
|
|
font-size: ${Constants.typescale.lvlN1};
|
2021-05-10 04:38:01 +03:00
|
|
|
font-family: ${Constants.font.semiBold};
|
2021-05-05 19:51:19 +03:00
|
|
|
font-weight: bold;
|
|
|
|
margin-top: 24px;
|
|
|
|
margin-bottom: 8px;
|
|
|
|
`;
|
|
|
|
|
2021-05-10 04:38:01 +03:00
|
|
|
export const ConfirmationModal = (props) => {
|
|
|
|
const [isEnabled, setIsEnabled] = useState(false);
|
2021-05-05 19:51:19 +03:00
|
|
|
|
2021-05-10 04:38:01 +03:00
|
|
|
const lang = {
|
|
|
|
deleteText: 'Delete',
|
|
|
|
confirmText: 'Confirm',
|
|
|
|
cancelText: 'Cancel'
|
|
|
|
}
|
2021-05-05 19:51:19 +03:00
|
|
|
|
2021-05-10 04:38:01 +03:00
|
|
|
const _handleChange = (e) => {
|
|
|
|
if (e.target.value === props.matchValue) {
|
|
|
|
setIsEnabled(true);
|
|
|
|
return;
|
2021-05-06 17:51:09 +03:00
|
|
|
}
|
2021-05-10 04:38:01 +03:00
|
|
|
setIsEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
let deleteButton = <ButtonWarningFull disabled={true}>{props.buttonText || lang.deleteText}</ButtonWarningFull>;
|
|
|
|
if (isEnabled) {
|
|
|
|
deleteButton = <ButtonWarningFull onClick={() => props.callback(true)}>{props.buttonText || lang.deleteText}</ButtonWarningFull>;
|
|
|
|
}
|
|
|
|
|
|
|
|
let confirmButton = <ButtonPrimaryFull disabled={true}>{props.buttonText || lang.confirmText}</ButtonPrimaryFull>;
|
|
|
|
if (isEnabled) {
|
|
|
|
confirmButton = <ButtonPrimaryFull onClick={() => props.callback(true)}>{props.buttonText || lang.confirmText}</ButtonPrimaryFull>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div css={STYLES_TRANSPARENT_BG}>
|
|
|
|
<Boundary enabled={true} onOutsideRectEvent={() => props.callback(false)}>
|
2021-05-05 19:51:19 +03:00
|
|
|
<div css={STYLES_MAIN_MODAL}>
|
2021-05-10 04:38:01 +03:00
|
|
|
<div css={STYLES_HEADER}>{props.header}</div>
|
|
|
|
<div css={STYLES_SUB_HEADER}>{props.subHeader}</div>
|
|
|
|
{props.type === "DELETE" &&
|
|
|
|
<>
|
|
|
|
{props.withValidation ? (
|
|
|
|
<>
|
|
|
|
<div css={STYLES_INPUT_HEADER}>{props.inputHeader}</div>
|
|
|
|
<Input placeholder={props.inputPlaceholder} onChange={_handleChange} />
|
|
|
|
<ButtonSecondaryFull onClick={() => props.callback(false)} style={{margin: '24px 0px 8px'}}>{lang.cancelText}</ButtonSecondaryFull>
|
|
|
|
{deleteButton}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<ButtonSecondaryFull onClick={() => props.callback(false)} style={{ margin: '24px 0px 8px' }}>{lang.cancelText}</ButtonSecondaryFull>
|
|
|
|
<ButtonWarningFull onClick={() => props.callback(true)}>{props.buttonText || lang.deleteText}</ButtonWarningFull>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
|
|
|
|
{props.type === "CONFIRM" &&
|
|
|
|
<>
|
|
|
|
{props.withValidation ? (
|
|
|
|
<>
|
|
|
|
<div css={STYLES_INPUT_HEADER}>{props.inputHeader}</div>
|
|
|
|
<Input placeholder={props.inputPlaceholder} onChange={_handleChange} />
|
|
|
|
<ButtonSecondaryFull onClick={() => props.callback(false)} style={{ margin: '24px 0px 8px' }}>{lang.cancelText}</ButtonSecondaryFull>
|
|
|
|
{confirmButton}
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<ButtonSecondaryFull onClick={() => props.callback(false)} style={{ margin: '24px 0px 8px' }}>{lang.cancelText}</ButtonSecondaryFull>
|
|
|
|
<ButtonPrimaryFull onClick={() => props.callback(true)}>{props.buttonText || lang.confirmText}</ButtonPrimaryFull>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
}
|
2021-05-05 19:51:19 +03:00
|
|
|
</div>
|
2021-05-10 04:38:01 +03:00
|
|
|
</Boundary>
|
|
|
|
</div>
|
|
|
|
);
|
2021-05-05 19:51:19 +03:00
|
|
|
};
|