-
Notifications
You must be signed in to change notification settings - Fork 514
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
Fix : Switch to using CreateFacilityForm #9662
Open
Mahendar0701
wants to merge
24
commits into
ohcnetwork:develop
Choose a base branch
from
Mahendar0701:facility-edit
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+105
−9
Open
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
03fd617
pincode updated
Mahendar0701 d1a6ca1
Merge branch 'develop' into facility-edit
Mahendar0701 7db9c3a
populated geo_organization values
Mahendar0701 080f442
Merge branch 'develop' into facility-edit
Mahendar0701 8159f13
Merge branch 'develop' into facility-edit
Mahendar0701 fc0413e
Merge branch 'develop' into facility-edit
Mahendar0701 d0daf9c
autofill of state and districts
Mahendar0701 f7db9bc
Merge branch 'develop' into facility-edit
Mahendar0701 02a4ca0
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 ab383d5
translation
Mahendar0701 7dff65f
commit
Mahendar0701 4eda986
added usequery
Mahendar0701 c811b60
Merge branch 'develop' into facility-edit
Mahendar0701 d9078ad
Merge branch 'develop' into facility-edit
Mahendar0701 884fc82
Merge branch 'develop' into facility-edit
Mahendar0701 0f49a53
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 b6b2318
Merge branch 'develop' into facility-edit
Mahendar0701 fd3241f
moved useFetchOrganizationByName organizationapi.ts
Mahendar0701 f9d4e49
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 3a9dcbf
Merge branch 'develop' into facility-edit
Mahendar0701 e87535d
Merge branch 'develop' into facility-edit
Mahendar0701 213eb95
Merge branch 'develop' into facility-edit
Mahendar0701 87db767
added conditions
Mahendar0701 4599c93
Merge branch 'facility-edit' of https://github.com/Mahendar0701/care_…
Mahendar0701 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import careConfig from "@careConfig"; | ||
import { | ||
Popover, | ||
PopoverButton, | ||
|
@@ -58,8 +59,13 @@ import * as Notification from "@/Utils/Notifications"; | |
import routes from "@/Utils/request/api"; | ||
import query from "@/Utils/request/query"; | ||
import request from "@/Utils/request/request"; | ||
import { parsePhoneNumber } from "@/Utils/utils"; | ||
import { | ||
getPincodeDetails, | ||
parsePhoneNumber, | ||
useFetchOrganizationByName, | ||
} from "@/Utils/utils"; | ||
import OrganizationSelector from "@/pages/Organization/components/OrganizationSelector"; | ||
import { Organization } from "@/types/organization/organization"; | ||
|
||
interface FacilityProps { | ||
facilityId?: string; | ||
|
@@ -68,6 +74,9 @@ export const FacilityCreate = (props: FacilityProps) => { | |
const { t } = useTranslation(); | ||
const { facilityId } = props; | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [selectedLevels, setSelectedLevels] = useState<Organization[]>([]); | ||
const [pincode, setPincode] = useState(""); | ||
|
||
const { goBack } = useAppHistory(); | ||
|
||
const facilityFormSchema = z.object({ | ||
|
@@ -146,7 +155,7 @@ export const FacilityCreate = (props: FacilityProps) => { | |
name: facilityData.name, | ||
description: facilityData.description || "", | ||
features: facilityData.features || [], | ||
pincode: facilityData.pincode, | ||
pincode: facilityData.pincode?.toString() || "", | ||
geo_organization: facilityData.geo_organization, | ||
address: facilityData.address, | ||
phone_number: facilityData.phone_number, | ||
|
@@ -212,9 +221,43 @@ export const FacilityCreate = (props: FacilityProps) => { | |
} | ||
}; | ||
|
||
const { data: pincodeData, isError: isPincodeError } = useQuery({ | ||
queryKey: ["pincodeDetails", pincode], | ||
queryFn: () => getPincodeDetails(pincode, careConfig.govDataApiKey), | ||
enabled: validatePincode(pincode), | ||
}); | ||
|
||
if (isPincodeError) { | ||
Notification.Error({ msg: "Invalid pincode" }); | ||
} | ||
|
||
Mahendar0701 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const stateName = pincodeData?.statename; | ||
|
||
const districtName = pincodeData?.districtname; | ||
|
||
const { data: stateOrg } = useFetchOrganizationByName(stateName); | ||
const { data: districtOrg } = useFetchOrganizationByName( | ||
districtName, | ||
stateOrg?.id, | ||
); | ||
|
||
useEffect(() => { | ||
if (stateOrg && districtOrg) { | ||
setSelectedLevels([stateOrg, districtOrg]); | ||
} else { | ||
setSelectedLevels([]); | ||
} | ||
}, [stateOrg, districtOrg]); | ||
|
||
console.log("selectedLevels", selectedLevels); | ||
|
||
const handlePincodeChange = (value: string) => { | ||
setPincode(value); | ||
}; | ||
Mahendar0701 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used usequery tanstack, is this approach acceptable?? |
||
return ( | ||
<Page | ||
title={facilityId ? "Update Facility" : "Create Facility"} | ||
title={facilityId ? t("update_facility") : t("create_facility")} | ||
crumbsReplacements={{ | ||
[facilityId || "????"]: { name: form.watch("name") }, | ||
}} | ||
|
@@ -318,6 +361,7 @@ export const FacilityCreate = (props: FacilityProps) => { | |
required | ||
onChange={(value) => { | ||
field.onChange(value.value); | ||
handlePincodeChange(value.value); | ||
}} | ||
error={form.formState.errors.pincode?.message} | ||
/> | ||
|
@@ -329,7 +373,12 @@ export const FacilityCreate = (props: FacilityProps) => { | |
<div className="col-span-2 grid grid-cols-2 gap-5"> | ||
<OrganizationSelector | ||
required={true} | ||
onChange={(value) => form.setValue("geo_organization", value)} | ||
value={facilityData?.geo_organization} | ||
parentSelectedLevels={selectedLevels} | ||
onChange={(value) => { | ||
// Update geo_organization value in form | ||
form.setValue("geo_organization", value); | ||
}} | ||
/> | ||
</div> | ||
|
||
|
@@ -411,7 +460,7 @@ export const FacilityCreate = (props: FacilityProps) => { | |
> | ||
<CareIcon icon="l-map-marker" className="text-xl" /> | ||
<span className="tooltip-text tooltip-bottom"> | ||
Select location from map | ||
{t("select_location_from")} | ||
</span> | ||
</Button> | ||
</PopoverButton> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bodhish @rithviknishad @Jacobjeevan you mean something like this?? #9711 (review)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to
types/organization/organizationApi
itself instead of defining it here.