Redirect when new msg group is created, and use contacts to push a new message from there

This commit is contained in:
J Francisco Rader committed 2021-02-16 17:10:45 -05:00
1 parent 3bf098c5ee
commit b93d5faee1
10 files changed
+195 -88

No files matched your search

@@ -1,4 +1,4 @@
import React, { FormEvent, useState } from 'react';
import React, { FormEvent, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { TextField, Button } from '@material-ui/core';
@@ -6,30 +6,44 @@ import useStyles from './form.styles';
import Nui from '../../../../os/nui-events/utils/Nui';
import { useHistory } from 'react-router-dom';
const NewMessageGroupForm = () => {
const sendNuiCreateMessageGroup = ({ parts, isGroupChat, labelValue }) =>
Nui.send('phone:createMessageGroup', {
asd: true,
phoneNumbers: parts,
label: isGroupChat && labelValue ? labelValue : null,
});
const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
const classes = useStyles();
const history = useHistory();
const { t } = useTranslation();
const [participants, setParticipants] = useState('');
const [participants, setParticipants] = useState(phoneNumber || '');
const [label, setLabel] = useState('');
useEffect(() => setParticipants(phoneNumber), [phoneNumber]);
// handles phone numbers in a csv format and strips all spaces and
// external characters out of them:
// 123-4567, 987-6543, 333-4444
const parts = participants
.split(',')
.map((part) => part.replace(/[^0-9]/g, ''));
const parts = useMemo(
() => participants.split(',').map((part) => part.replace(/[^0-9]/g, '')),
[participants]
);
const isGroupChat = parts.length > 1;
const labelValue = label.trim();
useEffect(() => {
if (phoneNumber && parts) {
sendNuiCreateMessageGroup({ parts, isGroupChat, labelValue });
history.push('/messages');
}
}, [isGroupChat, parts, phoneNumber, labelValue, history]);
const handleSubmit = (event: FormEvent) => {
event.preventDefault();
if (parts.length > 0) {
const labelValue = label.trim();
Nui.send('phone:createMessageGroup', {
phoneNumbers: parts,
label: isGroupChat && labelValue ? labelValue : null,
});
sendNuiCreateMessageGroup({ parts, isGroupChat, labelValue });
setParticipants('');
history.push('/messages');
}