-
Notifications
You must be signed in to change notification settings - Fork 19
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
O3-4250 (feat) Ability to add Cash Points and Payment modes via a UI #74
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,10 @@ import { | |
} from '@carbon/react'; | ||
import { Add } from '@carbon/react/icons'; | ||
import { useTranslation } from 'react-i18next'; | ||
import axios from 'axios'; | ||
import { useForm, Controller } from 'react-hook-form'; | ||
import { z } from 'zod'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { showSnackbar } from '@openmrs/esm-framework'; | ||
import { showSnackbar, openmrsFetch } from '@openmrs/esm-framework'; | ||
import { CardHeader } from '@openmrs/esm-patient-common-lib'; | ||
import styles from './payment-modes-config.scss'; | ||
|
||
|
@@ -38,7 +37,6 @@ const PaymentModesConfig: React.FC = () => { | |
const [isModalOpen, setIsModalOpen] = useState(false); | ||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); | ||
const [selectedPaymentMode, setSelectedPaymentMode] = useState(null); | ||
const baseUrl = `${window.location.origin}/openmrs/ws/rest/v1`; | ||
|
||
const { | ||
control, | ||
|
@@ -55,7 +53,7 @@ const PaymentModesConfig: React.FC = () => { | |
|
||
const fetchPaymentModes = useCallback(async () => { | ||
try { | ||
const response = await axios.get(`${baseUrl}/billing/paymentMode?v=full`); | ||
const response = await openmrsFetch('/ws/rest/v1/billing/paymentMode?v=full'); | ||
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. here too 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. Done |
||
setPaymentModes(response.data.results || []); | ||
} catch (err) { | ||
showSnackbar({ | ||
|
@@ -65,7 +63,7 @@ const PaymentModesConfig: React.FC = () => { | |
isLowContrast: false, | ||
}); | ||
} | ||
}, [baseUrl, t]); | ||
}, [t]); | ||
|
||
useEffect(() => { | ||
fetchPaymentModes(); | ||
|
@@ -89,20 +87,37 @@ const PaymentModesConfig: React.FC = () => { | |
} | ||
|
||
try { | ||
await axios.post(`${baseUrl}/billing/paymentMode`, { | ||
name: data.name, | ||
description: data.description, | ||
const response = await openmrsFetch('/ws/rest/v1/billing/paymentMode', { | ||
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. here too 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. Done |
||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
name: data.name, | ||
description: data.description, | ||
}), | ||
}); | ||
|
||
showSnackbar({ | ||
title: t('success', 'Success'), | ||
subtitle: t('paymentModeSaved', 'Payment mode was successfully saved.'), | ||
kind: 'success', | ||
}); | ||
if (response.ok) { | ||
showSnackbar({ | ||
title: t('success', 'Success'), | ||
subtitle: t('paymentModeSaved', 'Payment mode was successfully saved.'), | ||
kind: 'success', | ||
}); | ||
|
||
setIsModalOpen(false); | ||
reset({ name: '', description: '' }); | ||
fetchPaymentModes(); | ||
setIsModalOpen(false); | ||
reset({ name: '', description: '' }); | ||
fetchPaymentModes(); | ||
} else { | ||
const errorData = response.data || {}; | ||
showSnackbar({ | ||
title: t('error', 'Error'), | ||
subtitle: | ||
errorData.message || t('errorSavingPaymentMode', 'An error occurred while saving the payment mode.'), | ||
kind: 'error', | ||
isLowContrast: false, | ||
}); | ||
} | ||
} catch (err) { | ||
showSnackbar({ | ||
title: t('error', 'Error'), | ||
|
@@ -117,7 +132,9 @@ const PaymentModesConfig: React.FC = () => { | |
if (!selectedPaymentMode) return; | ||
|
||
try { | ||
await axios.delete(`${baseUrl}/billing/paymentMode/${selectedPaymentMode.uuid}`); | ||
await openmrsFetch(`/ws/rest/v1/billing/paymentMode/${selectedPaymentMode.uuid}`, { | ||
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. here too 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. Done |
||
method: 'DELETE', | ||
}); | ||
|
||
showSnackbar({ | ||
title: t('success', 'Success'), | ||
|
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.
you could use
restBaseUrl
otherthan completing the entire urlThere 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.
Done