mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-10 18:01:59 +00:00
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import React from 'react';
|
|
import { DialogContent } from 'components';
|
|
import { useCreateNotifyInvoiceBySMS, useInvoiceSMSDetail } from 'hooks/query';
|
|
|
|
const NotifyInvoiceViaSMSContext = React.createContext();
|
|
|
|
/**
|
|
* Invoice SMS notification provider.
|
|
*/
|
|
function NotifyInvoiceViaSMSFormProvider({ invoiceId, dialogName, ...props }) {
|
|
const [notificationType, setNotificationType] = React.useState('details');
|
|
|
|
// Retrieve the invoice sms notification message details.
|
|
const { data: invoiceSMSDetail, isLoading: isInvoiceSMSDetailLoading } =
|
|
useInvoiceSMSDetail(
|
|
invoiceId,
|
|
{
|
|
notification_key: notificationType,
|
|
},
|
|
{
|
|
enabled: !!invoiceId,
|
|
keepPreviousData: true,
|
|
},
|
|
);
|
|
// Create notfiy invoice by sms mutations.
|
|
const { mutateAsync: createNotifyInvoiceBySMSMutate } =
|
|
useCreateNotifyInvoiceBySMS();
|
|
|
|
// State provider.
|
|
const provider = {
|
|
invoiceId,
|
|
invoiceSMSDetail,
|
|
dialogName,
|
|
createNotifyInvoiceBySMSMutate,
|
|
|
|
notificationType,
|
|
setNotificationType,
|
|
};
|
|
|
|
return (
|
|
<DialogContent isLoading={isInvoiceSMSDetailLoading}>
|
|
<NotifyInvoiceViaSMSContext.Provider value={provider} {...props} />
|
|
</DialogContent>
|
|
);
|
|
}
|
|
|
|
const useNotifyInvoiceViaSMSContext = () =>
|
|
React.useContext(NotifyInvoiceViaSMSContext);
|
|
|
|
export { NotifyInvoiceViaSMSFormProvider, useNotifyInvoiceViaSMSContext };
|