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

Update Resource Forms to Enhance Validation #9062

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
46ec289
Update Resource Forms to Enhance Validation
JavidSumra Nov 8, 2024
9256e70
fix resource update test suit
JavidSumra Nov 9, 2024
41c1b1c
Merge branch 'develop' of github.com:JavidSumra/care_fe into issues/9…
JavidSumra Nov 9, 2024
5017f20
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 9, 2024
f68d453
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 11, 2024
9d3a9ba
Updated Handle Input to avoid Negative Value
JavidSumra Nov 19, 2024
098ba35
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 19, 2024
a5d862d
Remove Unnecessary Comments
JavidSumra Nov 19, 2024
7f5e000
Merge remote-tracking branch 'refs/remotes/origin/issues/9053/prevent…
JavidSumra Nov 19, 2024
fa5e529
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 20, 2024
fe78ab4
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
nihal467 Nov 20, 2024
de7d829
Add Requested Changes
JavidSumra Nov 21, 2024
6440d4b
Merge remote-tracking branch 'refs/remotes/origin/issues/9053/prevent…
JavidSumra Nov 21, 2024
2c98d02
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 22, 2024
bfaf9ce
Fix Min Value issue in Resource Create/Update Form
JavidSumra Nov 26, 2024
8c9ae68
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 26, 2024
f3d396d
Merge branch 'develop' of https://github.com/JavidSumra/care_fe into …
JavidSumra Nov 26, 2024
0dcc585
Fix sanitize function
JavidSumra Nov 26, 2024
32d5b35
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Nov 26, 2024
5a0b57f
Fix Min Value Error issue in Resource Form Fields
JavidSumra Nov 26, 2024
e98f12d
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 27, 2024
13d19e0
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 27, 2024
03f2fcb
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 27, 2024
706c5b0
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 28, 2024
356f516
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 28, 2024
c910c84
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Nov 29, 2024
47804a5
Merge branch 'develop' of https://github.com/JavidSumra/care_fe into …
JavidSumra Nov 30, 2024
83d3113
Fix 0 Value on Resourse Request
JavidSumra Nov 30, 2024
27847a9
Merge branch 'ohcnetwork:develop' into issues/9053/prevent-negative-q…
JavidSumra Nov 30, 2024
d7e44c0
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Nov 30, 2024
1936cef
Fix Approved Quntity Issue
JavidSumra Dec 5, 2024
eff793d
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 5, 2024
a6d9740
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 5, 2024
3f03744
Merge branch 'develop' of https://github.com/JavidSumra/care_fe into …
JavidSumra Dec 5, 2024
be9d71c
Fix Validation
JavidSumra Dec 5, 2024
5512d94
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Dec 5, 2024
15cc8d6
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 5, 2024
31bc4f1
Add Suggestions
JavidSumra Dec 5, 2024
99cbac8
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Dec 5, 2024
506c212
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 5, 2024
43c635d
Add Translation and Revert to switch case logic
JavidSumra Dec 5, 2024
0230bcb
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Dec 5, 2024
633530d
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 5, 2024
10a34f2
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 7, 2024
08ac2c9
Add Requested Changes
JavidSumra Dec 9, 2024
83d4031
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Dec 9, 2024
b584e6d
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 9, 2024
c5624e9
Fix Failing Test
JavidSumra Dec 9, 2024
e1d0a76
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Dec 9, 2024
1033d25
Fix error state for assigned facility
JavidSumra Dec 9, 2024
94f6607
Add Requested Changes
JavidSumra Dec 10, 2024
c689d1b
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 10, 2024
2fd83cc
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 10, 2024
995618a
Fix Placeholder issue
JavidSumra Dec 10, 2024
8fd7a56
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Dec 10, 2024
7f82661
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 11, 2024
4e9d0cb
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 11, 2024
ea06d20
Fix Merger Conflicts
JavidSumra Dec 13, 2024
d37047a
Merge branch 'issues/9053/prevent-negative-quantity-and-empty-descrip…
JavidSumra Dec 13, 2024
d84c341
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 13, 2024
650149a
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 13, 2024
e55ae0c
Merge branch 'develop' into issues/9053/prevent-negative-quantity-and…
JavidSumra Dec 14, 2024
785bfa4
Fix Merge Conflict
JavidSumra Dec 16, 2024
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
6 changes: 5 additions & 1 deletion cypress/e2e/resource_spec/ResourcesHomepage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import LoginPage from "../../pageobject/Login/LoginPage";
import ResourcePage from "../../pageobject/Resource/ResourcePage";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";

describe("Resource Page", () => {
let createdResource: string;
Expand Down Expand Up @@ -68,6 +68,10 @@ describe("Resource Page", () => {
cy.visit(createdResource);
resourcePage.clickUpdateStatus();
resourcePage.updateStatus("APPROVED");
cy.clickAndSelectOption(
"input[name='assigned_facility_object']",
"Dummy Request Fulfilment Center, Ernakulam",
);
resourcePage.clickSubmitButton();
resourcePage.verifySuccessNotification(
"Resource request updated successfully",
Expand Down
4 changes: 4 additions & 0 deletions src/components/Form/FormFields/TextFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type TextFormFieldProps = FormFieldBaseProps<string> &
trailingPadding?: string | undefined;
leadingPadding?: string | undefined;
suggestions?: string[];
min?: number | string;
max?: number | string;
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
clearable?: boolean | undefined;
};

Expand Down Expand Up @@ -63,6 +65,8 @@ const TextFormField = forwardRef((props: TextFormFieldProps, ref) => {
type={props.type === "password" ? getPasswordFieldType() : props.type}
name={field.name}
value={field.value}
min={Number(props?.min)}
max={Number(props?.max)}
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
required={field.required}
onChange={(e) => field.handleChange(e.target.value)}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Resource/ResourceCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ export default function ResourceCreate(props: resourceProps) {
<TextFormField
label={t("required_quantity")}
name="requested_quantity"
type="number"
min={1}
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
value={state.form.required_quantity}
onChange={handleChange}
/>
Expand Down
34 changes: 26 additions & 8 deletions src/components/Resource/ResourceDetailsUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ const requiredFields: any = {
approving_facility_object: {
errorText: "Resource approving facility can not be empty.",
},
assigned_facility_type: {
assigned_facility_object: {
errorText: "Please Select Facility Type",
},
title: {
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
errorText: "Title is required.",
},
reason: {
errorText: "Description is required.",
},
};

const initError = Object.assign(
Expand Down Expand Up @@ -101,7 +107,15 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
const errors = { ...initError };
let isInvalidForm = false;
Object.keys(requiredFields).forEach((field) => {
if (!state.form[field] || !state.form[field].length) {
if (
field === "approving_facility_object" ||
field === "assigned_facility_object"
) {
if (!state.form[field] || !state.form[field]?.name) {
errors[field] = requiredFields[field].errorText;
isInvalidForm = true;
}
} else if (!state.form[field] || state.form[field].trim().length === 0) {
errors[field] = requiredFields[field].errorText;
isInvalidForm = true;
}
Expand Down Expand Up @@ -144,7 +158,7 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
});

const handleSubmit = async () => {
const validForm = validateForm();
const validForm = !validateForm();
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved

if (validForm) {
setIsLoading(true);
Expand Down Expand Up @@ -233,7 +247,7 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
setSelected={(obj) =>
setFacility(obj, "approving_facility_object")
}
errors={state.errors.approving_facility}
errors={state.errors.approving_facility_object}
/>
</div>

Expand All @@ -243,20 +257,21 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
</FieldLabel>
<FacilitySelect
multiple={false}
name="assigned_facility"
name="assigned_facility_object"
facilityType={1510}
selected={state.form.assigned_facility_object}
setSelected={(obj) =>
setFacility(obj, "assigned_facility_object")
}
errors={state.errors.assigned_facility}
errors={state.errors.assigned_facility_object}
/>
</div>
<div>
<TextFormField
label="Required Quantity"
name="requested_quantity"
type="number"
min={1}
value={state.form.requested_quantity}
onChange={handleChange}
/>
Expand All @@ -265,6 +280,7 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
<TextFormField
name="assigned_quantity"
type="number"
min={1}
label="Approved Quantity"
value={state.form.assigned_quantity}
onChange={handleChange}
Expand All @@ -276,11 +292,12 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
<TextFormField
name="title"
type="text"
label="Request Title*"
label="Request Title"
placeholder="Type your title here"
value={state.form.title}
onChange={handleChange}
error={state.errors.title}
required
/>
</div>

Expand All @@ -291,8 +308,9 @@ export const ResourceDetailsUpdate = (props: resourceProps) => {
placeholder="Type your description here"
value={state.form.reason}
onChange={handleChange}
label="Description of request*"
label="Description of request"
error={state.errors.reason}
required
/>
</div>

Expand Down
Loading