mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: add notify via SMS Form.
This commit is contained in:
42
src/containers/NotifyViaSMS/NotifyViaSMSForm.js
Normal file
42
src/containers/NotifyViaSMS/NotifyViaSMSForm.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import React from 'react';
|
||||
import { Formik, Form } from 'formik';
|
||||
|
||||
import 'style/pages/NotifyConactViaSMS/NotifyConactViaSMSDialog.scss';
|
||||
|
||||
import { CreateNotifyViaSMSFormSchema } from './NotifyViaSMSForm.schema';
|
||||
import NotifyViaSMSFormFields from './NotifyViaSMSFormFields';
|
||||
import NotifyViaSMSFormFloatingActions from './NotifyViaSMSFormFloatingActions';
|
||||
|
||||
import { transformToForm, saveInvoke } from 'utils';
|
||||
|
||||
const defaultInitialValues = {
|
||||
customer_name: '',
|
||||
customer_personal_phone: '',
|
||||
sms_message: '',
|
||||
};
|
||||
|
||||
/**
|
||||
* Notify Via SMS Form.
|
||||
*/
|
||||
function NotifyViaSMSForm({ onSubmit, NotificationDetail, NotificationName }) {
|
||||
// Initial form values
|
||||
const initialValues = {
|
||||
...defaultInitialValues,
|
||||
...transformToForm(NotificationDetail, defaultInitialValues),
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={CreateNotifyViaSMSFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
<Form>
|
||||
<NotifyViaSMSFormFields />
|
||||
<NotifyViaSMSFormFloatingActions dialogName={NotificationName} />
|
||||
</Form>
|
||||
</Formik>
|
||||
);
|
||||
}
|
||||
|
||||
export default NotifyViaSMSForm;
|
||||
11
src/containers/NotifyViaSMS/NotifyViaSMSForm.schema.js
Normal file
11
src/containers/NotifyViaSMS/NotifyViaSMSForm.schema.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import * as Yup from 'yup';
|
||||
import intl from 'react-intl-universal';
|
||||
import { DATATYPES_LENGTH } from 'common/dataTypes';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
customer_name: Yup.string().required(),
|
||||
customer_personal_phone: Yup.number().required(),
|
||||
sms_message: Yup.string().required().trim().max(DATATYPES_LENGTH.TEXT),
|
||||
});
|
||||
|
||||
export const CreateNotifyViaSMSFormSchema = Schema;
|
||||
79
src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js
Normal file
79
src/containers/NotifyViaSMS/NotifyViaSMSFormFields.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import React from 'react';
|
||||
import { FastField, ErrorMessage } from 'formik';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
|
||||
import { Classes, FormGroup, TextArea, InputGroup } from '@blueprintjs/core';
|
||||
import classNames from 'classnames';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import { inputIntent } from 'utils';
|
||||
import { FieldRequiredHint } from 'components';
|
||||
|
||||
function NotifyViaSMSFormFields() {
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
{/* ----------- Send Notification to ----------- */}
|
||||
<FastField name={'customer_name'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'notify_via_sms.dialog.send_notification_to'} />}
|
||||
className={classNames('form-group--customer-name', CLASSES.FILL)}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'customer_name'} />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
disabled={true}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ----------- Phone number ----------- */}
|
||||
<FastField name={'customer_personal_phone'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'phone_number'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="customer_personal_phone" />}
|
||||
className={classNames(
|
||||
'form-group--customer_personal_phone',
|
||||
CLASSES.FILL,
|
||||
)}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
disabled={true}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ----------- Message Text ----------- */}
|
||||
<FastField name={'sms_message'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'notify_via_sms.dialog.message_text'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={'form-group--sms_message'}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'sms_message'} />}
|
||||
>
|
||||
<TextArea
|
||||
growVertically={true}
|
||||
large={true}
|
||||
disabled={true}
|
||||
intent={inputIntent({ error, touched })}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default NotifyViaSMSFormFields;
|
||||
@@ -0,0 +1,41 @@
|
||||
import React from 'react';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
|
||||
import { FormattedMessage as T } from 'components';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
function NotifyViaSMSFormFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
dialogName,
|
||||
}) {
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
// Handle close button click.
|
||||
const handleCancelBtnClick = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '75px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
loading={isSubmitting}
|
||||
style={{ minWidth: '75px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'send'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(NotifyViaSMSFormFloatingActions);
|
||||
Reference in New Issue
Block a user