Skip to content

Commit

Permalink
Merge pull request #234 from popovaevgeniya/019-nov-10-input-value-va…
Browse files Browse the repository at this point in the history
…lidation-for-the-project

019 nov 10 input value validation for the project
  • Loading branch information
MuhammadKhalilzadeh authored Nov 12, 2024
2 parents be85b86 + 36084c5 commit f2769a0
Show file tree
Hide file tree
Showing 15 changed files with 909 additions and 394 deletions.
29 changes: 29 additions & 0 deletions Clients/src/application/validations/selectValidation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Converts feedback information into an object containing acceptance status and a message.
*
* @param accepted - A boolean indicating whether the feedback is accepted.
* @param message - A string containing the feedback message.
* @returns An object with `accepted` and `message` properties.
*/
function feedback(accepted: boolean, message: string) {
return {
accepted,
message,
};
}

/**
* Select field validation
*
* @param value - The value to be validated.
* @returns An object with `accepted` set to `true` if the value passes all validations,
* otherwise an object with `accepted` set to `false` and a `message` indicating the reason.
*/
function selectValidation(title: string, value: number): {accepted: boolean; message: string} {
if (value === 0) {
return feedback(false, `${title} is required.`);
}
return feedback(true, "Success");
}

export default selectValidation;
5 changes: 3 additions & 2 deletions Clients/src/application/validations/stringValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ export function checkStringValidation(
type?: string
): { accepted: boolean; message: string } {
if (
value.length === 0 ||
(value.length === 0 ||
value === undefined ||
value === null ||
value === "" ||
value === " "
value === " ") &&
minLength > 0
) {
return feedbackToString(false, `${title} is required.`);
}
Expand Down

Large diffs are not rendered by default.

416 changes: 279 additions & 137 deletions Clients/src/presentation/components/AddNewRiskForm/RisksSection/index.tsx

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions Clients/src/presentation/components/AddNewRiskForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import RiskSection from "./RisksSection";
import MitigationSection from "./MitigationSection";
import "./styles.css"

const AddNewRiskForm: FC = () => {
interface AddNewRiskFormProps {
closePopup: () => void
}

const AddNewRiskForm: FC<AddNewRiskFormProps> = ({closePopup}) => {
const theme = useTheme();
const disableRipple = theme.components?.MuiButton?.defaultProps?.disableRipple;

Expand All @@ -26,7 +30,7 @@ const AddNewRiskForm: FC = () => {
};

return (
<Stack component="form" noValidate>
<Stack>
<TabContext value={value}>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
<TabList onChange={handleChange} aria-label="Add new risk tabs"
Expand All @@ -39,8 +43,8 @@ const AddNewRiskForm: FC = () => {
<Tab label="Mitigation" value="mitigation" sx={tabStyle} disableRipple={disableRipple} />
</TabList>
</Box>
<TabPanel value="risks" sx={{ p: "24px 0 0" }}><RiskSection /></TabPanel>
<TabPanel value="mitigation" sx={{ p: "24px 0 0" }}><MitigationSection /></TabPanel>
<TabPanel value="risks" sx={{ p: "24px 0 0" }}><RiskSection closePopup={closePopup} /></TabPanel>
<TabPanel value="mitigation" sx={{ p: "24px 0 0" }}><MitigationSection closePopup={closePopup} /></TabPanel>
</TabContext>
</Stack>
)
Expand Down
Loading

0 comments on commit f2769a0

Please sign in to comment.