Skip to content

Commit

Permalink
Pending form transition in form Add
Browse files Browse the repository at this point in the history
  • Loading branch information
ertush committed Jan 12, 2024
1 parent d734930 commit c48f1bf
Show file tree
Hide file tree
Showing 25 changed files with 309 additions and 360 deletions.
102 changes: 51 additions & 51 deletions components/FacilityDetailsTabs.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions components/FacilityDetailsTabsPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function FacilityDetailsTabsPulic({ facility }) {
let rating_val = [];
rating_val[0] = data.rating;
rating_val[1] = data.comment;
alert.success({timeout: 10000}, "Review submitted successfully");
alert.success("Review submitted successfully");
window.localStorage.setItem("rating", JSON.stringify(rating_val));

//clear
Expand All @@ -78,7 +78,7 @@ function FacilityDetailsTabsPulic({ facility }) {
console.log(error);
}
} else {
alert.error({timeout: 10000}, "Rating value must be greater than zero");
alert.error("Rating value must be greater than zero");
}
};

Expand Down
2 changes: 1 addition & 1 deletion components/FacilityUpdatesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function FacilityUpdatesTable({ facilityUpdatedJson, originalData }) {


return (
<Table className="md:px-4">
<Table className="md:px-4 mt-4">

{/* Switch FacilityTableUpdates View */}
<TableBody className='w-full flex flex-col gap-y-6'>
Expand Down
8 changes: 4 additions & 4 deletions components/Forms/BasicDetailsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export function BasicDeatilsForm({ editMode }) {
})
.then(res => {
if (res.status == 204 || res.status == 200) {
alert.success({timeout: 10000}, 'Facility Updated Successfully')
alert.success('Facility Updated Successfully')
setSubmitting(false)

router.push({
Expand All @@ -335,7 +335,7 @@ export function BasicDeatilsForm({ editMode }) {
})

} else {
alert.error({timeout: 10000}, 'Unable to update facility')
alert.error('Unable to update facility')
setSubmitting(false)
res.json()
.then(resp => {
Expand Down Expand Up @@ -392,10 +392,10 @@ export function BasicDeatilsForm({ editMode }) {

if (res.status == 201 || res.status == 200) {
setSubmitting(false)
alert.success({timeout: 10000}, 'Facility Added Successfully')
alert.success('Facility Added Successfully')
} else {
setSubmitting(false)
alert.error({timeout: 10000}, 'Unable to Add facility')
alert.error('Unable to Add facility')
res.json()
.then(resp => {
const formResponse = []
Expand Down
12 changes: 5 additions & 7 deletions components/Forms/CommunityUnitsForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ function EditCommunityUnitsBasicDeatilsForm(props) {

setSubmitting(false)
// setFormError(Array.isArray(Object.values(detail)) && Object.values(detail).length == 1 && typeof Object.values(detail)[0] == 'string' && detail[0][0])
alert.error({timeout: 10000}, 'Unable to save Community Units Basic details')
alert.error('Unable to save Community Units Basic details')
}
})
}

catch (e) {
alert.error({timeout: 10000}, 'Error Occured: ' + e.message)
alert.error('Error Occured: ' + e.message)
}


Expand Down Expand Up @@ -695,13 +695,13 @@ function EditCommunityUnitsCHEWSForm(props) {

setSubmitting(false)
// setFormError(Array.isArray(Object.values(detail)) && Object.values(detail).length == 1 && typeof Object.values(detail)[0] == 'string' && detail[0][0])
alert.error({timeout: 10000}, 'Unable to update Community Units healtjh workers')
alert.error('Unable to update Community Units healtjh workers')
}
})
}

catch (e) {
alert.error({timeout: 10000}, 'Error Occured: ' + e.message)
alert.error('Error Occured: ' + e.message)
}
}

Expand Down Expand Up @@ -751,7 +751,7 @@ function EditCommunityUnitsCHEWSForm(props) {
// setDeleteButton(props?.health_unit_workers.map((_, i) => ({[i]: false})))


alert.success({timeout: 10000}, `${props?.health_unit_workers[index]?.name} has been deleted successfully`)
alert.success(`${props?.health_unit_workers[index]?.name} has been deleted successfully`)
} else {
resp.json().then(({detail}) => {
alert.error('Unable to delete health worker', {timeout: 10000})
Expand Down Expand Up @@ -922,12 +922,10 @@ function EditCommunityUnitsCHEWSForm(props) {

}


function EditCommunityUnitsServicesForm(props) {

const currentServices = props?.services?.map(({name: label, service: value}) => ({label, value})) ?? []


const options = useContext(ChuOptionsContext)

const [submitting, setSubmitting] = useState(false)
Expand Down
10 changes: 5 additions & 5 deletions components/Forms/FacilityContactsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export function FacilityContactsForm() {
.then((resp) => {
defer(() => updatedSavedChanges(true));
if (resp.status == 200 || resp.status == 204) {
alert.success({timeout: 10000}, "Updated facility contacts successfully")
alert.success("Updated facility contacts successfully")

router.push({
pathname: '/facilities/facility_changes/[facility_id]',
Expand All @@ -257,7 +257,7 @@ export function FacilityContactsForm() {
}

else {
alert.error({timeout: 10000}, "Unable to update facility contacts")
alert.error("Unable to update facility contacts")
resp.json()
.then(resp => {
const formResponse = []
Expand Down Expand Up @@ -297,7 +297,7 @@ export function FacilityContactsForm() {
}
})

alert.success({timeout: 10000}, 'Officer Incharge Contacts Saved successfully')
alert.success('Officer Incharge Contacts Saved successfully')

const formDataBase64Enc = Buffer.from(JSON.stringify(values)).toString('base64')

Expand Down Expand Up @@ -326,8 +326,8 @@ export function FacilityContactsForm() {
}
else {
setSubmitting(false)
alert.error({timeout: 10000}, 'Unable to save Facility Contacts')
alert.error({timeout: 10000}, 'Unable to save Officer Incharge Contacts')
alert.error('Unable to save Facility Contacts')
alert.error('Unable to save Officer Incharge Contacts')

resp.json()
.then(resp => {
Expand Down
7 changes: 4 additions & 3 deletions components/Forms/GeolocationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export function GeolocationForm({ editMode }) {
longitude: Number(data?.longitude),
facility: options?.data?.id
}


if (payload) {

Expand All @@ -118,12 +117,14 @@ export function GeolocationForm({ editMode }) {
if (resp.status == 200 || resp.status == 201) {
alert.success('Geolocation Detatils saved Successfully', {timeout: 10000})
setSubmitting(false)

router.push({
pathname: '/facilities/facility_changes/[facility_id]/',
query: {
facility_id: options?.data?.id
}
})

} else {
alert.error('Unable to save Geolocation Details Successfully', {timeout: 10000})
setSubmitting(false)
Expand Down Expand Up @@ -181,7 +182,7 @@ export function GeolocationForm({ editMode }) {
})
.then(res => {
if (res.status == 204 || res.status == 200) {
alert.success({timeout: 10000}, 'Facility Geolocation Details have been saved successfully')
alert.success('Facility Geolocation Details have been saved successfully')

setSubmitting(false)

Expand Down Expand Up @@ -216,7 +217,7 @@ export function GeolocationForm({ editMode }) {

} else {
setSubmitting(false)
alert.error({timeout: 10000}, 'Unable to save to Geolocation details')
alert.error('Unable to save to Geolocation details')

res.json()
.then(resp => {
Expand Down
12 changes: 6 additions & 6 deletions components/Forms/formComponents/EditListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function EditListItem({
.then(resp => {
if (resp.status == 200 || resp.status == 204) {
setSubmitting(false)
alert.success({timeout: 10000}, 'Updated facility services successfully');
alert.success('Updated facility services successfully');

router.push({
pathname: '/facilities/facility_changes/[facility_id]',
Expand Down Expand Up @@ -195,7 +195,7 @@ function EditListItem({
.then(resp => {
if (resp.status == 200 || resp.status == 204) {
setSubmitting(false)
alert.success({timeout: 10000}, 'Updated Community Health Unit Services successfully');
alert.success('Updated Community Health Unit Services successfully');

// router.push({
// pathname: '/facilities/facility_changes/[facility_id]',
Expand Down Expand Up @@ -232,7 +232,7 @@ function EditListItem({
if (resp.status == 204 || resp.status == 200) {
if(itemName == "facility_services") {
setSubmitting(false)
alert.success({timeout: 10000}, 'Facility services saved successfully');
alert.success('Facility services saved successfully');

const services = typeof selectedItems == 'string' ? JSON.parse(selectedItems).map(({ rowid }) => ({ service: rowid })) : selectedItems.map(({ rowid }) => ({ service: rowid }))
const payload = JSON.stringify(services)
Expand Down Expand Up @@ -280,7 +280,7 @@ function EditListItem({
}
else {
setSubmitting(false)
alert.error({timeout: 10000}, 'Unable to save facility services');
alert.error('Unable to save facility services');

resp.json()
.then(resp => {
Expand All @@ -306,7 +306,7 @@ function EditListItem({
.then(resp => {
if (resp.status == 204 || resp.status == 200) {
setSubmitting(false)
alert.success({timeout: 10000}, 'Community health unit services saved successfully');
alert.success('Community health unit services saved successfully');
console.log(' Navigating to CHU Details page ... ')

router.push({
Expand All @@ -319,7 +319,7 @@ function EditListItem({
}
else {
setSubmitting(false)
alert.error({timeout: 10000}, 'Unable to save Community Health Unit Services');
alert.error('Unable to save Community Health Unit Services');

}
})
Expand Down
12 changes: 6 additions & 6 deletions components/Forms/formComponents/EditListWithCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function EditListWithCount(
.then(resp => {
if (resp.status == 200 || resp.status == 204) {
setSubmitting(false)
alert.success({timeout: 10000}, `Facility ${e.target.name.includes("infrastructure") ? 'Infrastructure' : 'Human resource'} form updated successfully`)
alert.success(`Facility ${e.target.name.includes("infrastructure") ? 'Infrastructure' : 'Human resource'} form updated successfully`)

router.push({
pathname: '/facilities/facility_changes/[facility_id]',
Expand All @@ -288,7 +288,7 @@ function EditListWithCount(

} else {
setSubmitting(false)
alert.error({timeout: 10000}, `Unable to update facility ${e.target.name.includes("infrastructure") ? 'Infrastructure' : 'Human resource'}`)
alert.error(`Unable to update facility ${e.target.name.includes("infrastructure") ? 'Infrastructure' : 'Human resource'}`)

resp.json()
.then(resp => {
Expand Down Expand Up @@ -317,13 +317,13 @@ function EditListWithCount(
.then(resp => {
if (resp.status == 204 || resp.status == 200) {
setSubmitting(false)
alert.success({timeout: 10000}, 'Facility humanresource saved successfully')
alert.success('Facility humanresource saved successfully')

router.push(`/facilities/${itemId}`)

} else {
setSubmitting(false)
alert.error({timeout: 10000}, 'Unable to save facility humanresource')
alert.error('Unable to save facility humanresource')
resp.json()
.then(resp => {
const formResponse = []
Expand All @@ -347,7 +347,7 @@ function EditListWithCount(
.then(resp => {
if (resp.status == 204 || resp.status == 200) {
setSubmitting(false)
alert.success({timeout: 10000}, 'Facility Infrastructure saved successfully')
alert.success('Facility Infrastructure saved successfully')

const infrastructure = selectedRows.map(({ rowid }) => ({ service: rowid }))

Expand Down Expand Up @@ -381,7 +381,7 @@ function EditListWithCount(
} else {

setSubmitting(false)
alert.error({timeout: 10000}, 'Unable to save facility infrastructure')
alert.error('Unable to save facility infrastructure')
resp.json()
.then(resp => {
const formResponse = []
Expand Down
2 changes: 1 addition & 1 deletion components/Forms/formComponents/FacilityContacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const FacilityContact = ({contactTypeOptions, setFacilityContacts, index, fieldN
try{
if(contactTypeRef?.current) {
const resp = await fetch(`/api/common/submit_form_data/?path=delete_contact&id=${contactTypeRef?.current?.state?.value[0].id ?? null}`)
if(resp.status == 204) alert.success({timeout: 10000}, 'Deleted Facility Contact Successfully')
if(resp.status == 204) alert.success('Deleted Facility Contact Successfully')


}
Expand Down
9 changes: 7 additions & 2 deletions components/Forms/formComponents/FacilityDepartmentUnits.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export default function FacilityDepartmentUnits({facilityDeptOptions, setFacili

const facilityDepts = useContext(FacilityDepartmentUnitsContext);


console.log(facilityDepts)


return (
<>


{/* Name */}
<Select options={facilityDeptOptions || []}
Expand All @@ -36,7 +38,10 @@ export default function FacilityDepartmentUnits({facilityDeptOptions, setFacili
onClick={(ev) => {
ev.preventDefault();
facilityDepts.splice(index, 1);
setFacilityDepts(facilityDepts);
// setFacilityDepts(prev => {
// return prev.filter(({id}) => id )
// });
return facilityDepts

}}><XCircleIcon className='w-7 h-7 text-red-400' /></button>

Expand Down
Loading

0 comments on commit c48f1bf

Please sign in to comment.