mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Optimize SMS notification module.
This commit is contained in:
@@ -44,7 +44,6 @@ function SMSMessageForm({
|
||||
...omit(values, ['is_notification_enabled', 'sms_message']),
|
||||
notification_key: smsNotification.key,
|
||||
};
|
||||
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {
|
||||
AppToaster.show({
|
||||
@@ -53,7 +52,6 @@ function SMSMessageForm({
|
||||
});
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
@@ -62,7 +60,7 @@ function SMSMessageForm({
|
||||
}) => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
debugger;
|
||||
editSMSNotificationMutate(form).then(onSuccess).catch(onError);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,17 +1,103 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
import { Form, useFormikContext } from 'formik';
|
||||
import styled from 'styled-components';
|
||||
import { Classes } from '@blueprintjs/core';
|
||||
|
||||
import SMSMessageFormFields from './SMSMessageFormFields';
|
||||
import SMSMessageFormFloatingActions from './SMSMessageFormFloatingActions';
|
||||
|
||||
import { SMSMessagePreview } from 'components';
|
||||
import { getSMSUnits } from '../../NotifyViaSMS/utils';
|
||||
|
||||
const messageVariables = [
|
||||
{
|
||||
variable: '{CompanyName}',
|
||||
description: 'References to the current company name.',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* SMS message form content.
|
||||
*/
|
||||
export default function SMSMessageFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<SMSMessageFormFields />
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<FormContent>
|
||||
<FormFields>
|
||||
<SMSMessageFormFields />
|
||||
|
||||
<SMSMessageVariables>
|
||||
{messageVariables.map(({ variable, description }) => (
|
||||
<MessageVariable>
|
||||
<strong>{variable}</strong> {description}
|
||||
</MessageVariable>
|
||||
))}
|
||||
</SMSMessageVariables>
|
||||
</FormFields>
|
||||
|
||||
<FormPreview>
|
||||
<SMSMessagePreviewSection />
|
||||
</FormPreview>
|
||||
</FormContent>
|
||||
</div>
|
||||
<SMSMessageFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SMS Message preview section.
|
||||
* @returns {JSX}
|
||||
*/
|
||||
function SMSMessagePreviewSection() {
|
||||
const {
|
||||
values: { message_text: message },
|
||||
} = useFormikContext();
|
||||
|
||||
const messagesUnits = getSMSUnits(message);
|
||||
|
||||
return (
|
||||
<SMSPreviewSectionRoot>
|
||||
<SMSMessagePreview message={message} />
|
||||
|
||||
<SMSPreviewSectionNote>
|
||||
<strong>Note</strong>: Note: One SMS unit can contain a maximum of 160
|
||||
characters. <strong>{messagesUnits}</strong> SMS units will be used to
|
||||
send this SMS notification.
|
||||
</SMSPreviewSectionNote>
|
||||
</SMSPreviewSectionRoot>
|
||||
);
|
||||
}
|
||||
|
||||
const SMSPreviewSectionRoot = styled.div``;
|
||||
|
||||
const SMSPreviewSectionNote = styled.div`
|
||||
font-size: 12px;
|
||||
opacity: 0.7;
|
||||
`;
|
||||
|
||||
const SMSMessageVariables = styled.div`
|
||||
list-style: none;
|
||||
font-size: 12px;
|
||||
opacity: 0.9;
|
||||
`;
|
||||
|
||||
const MessageVariable = styled.div`
|
||||
margin-bottom: 8px;
|
||||
`;
|
||||
|
||||
const FormContent = styled.div`
|
||||
display: flex;
|
||||
`;
|
||||
const FormFields = styled.div`
|
||||
width: 55%;
|
||||
`;
|
||||
const FormPreview = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 45%;
|
||||
padding-left: 25px;
|
||||
margin-left: 25px;
|
||||
border-left: 1px solid #dcdcdd;
|
||||
`;
|
||||
|
||||
@@ -7,7 +7,7 @@ import { inputIntent } from 'utils';
|
||||
|
||||
export default function SMSMessageFormFields() {
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<div>
|
||||
{/* ----------- Message Text ----------- */}
|
||||
<FastField name={'message_text'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { useFormikContext } from 'formik';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { FormattedMessage as T } from 'components';
|
||||
|
||||
import { useSMSMessageDialogContext } from './SMSMessageDialogProvider';
|
||||
@@ -27,7 +29,7 @@ function SMSMessageFormFloatingActions({
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<FooterActions className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '75px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
@@ -37,11 +39,15 @@ function SMSMessageFormFloatingActions({
|
||||
style={{ minWidth: '75px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'save'} />}
|
||||
Save SMS Message
|
||||
</Button>
|
||||
</div>
|
||||
</FooterActions>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(SMSMessageFormFloatingActions);
|
||||
|
||||
const FooterActions = styled.div`
|
||||
justify-content: flex-start;
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user