mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-02 22:17:39 +00:00
remove(phone/messages): remove alerts components
This commit is contained in:
1 parent
796548d9d5
commit
ec913fbef4
3 files changed
+45
-101
No files matched your search
@@ -1,75 +0,0 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Snackbar } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
|
||||
import useAlerts from '../hooks/useAlerts';
|
||||
import Alert from '../../../ui/components/Alert';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
width: '100%',
|
||||
bottom: '60px',
|
||||
position: 'absolute',
|
||||
},
|
||||
}));
|
||||
|
||||
const ALERT_TIMEOUT = 6000;
|
||||
|
||||
export default function AlertBar() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { createMessageGroupResult } = useAlerts();
|
||||
const [severity, setSeverity] = useState<string | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const [alert, setAlert] = useState(null);
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
setAlert(null);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (createMessageGroupResult) {
|
||||
setAlert(createMessageGroupResult);
|
||||
}
|
||||
}, [createMessageGroupResult]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!alert) return;
|
||||
|
||||
const { error, phoneNumber, duplicate, mine } = alert;
|
||||
if (error && phoneNumber) {
|
||||
const error = `${t('APPS_MESSAGES_INVALID_PHONE_NUMBER')}${phoneNumber}`;
|
||||
setOpen(true);
|
||||
setSeverity('error');
|
||||
setMessage(error);
|
||||
} else if (error && duplicate) {
|
||||
setOpen(true);
|
||||
setSeverity('error');
|
||||
setMessage(t('APPS_MESSAGES_MESSAGE_GROUP_DUPLICATE'));
|
||||
} else if (error && mine) {
|
||||
setOpen(true);
|
||||
setSeverity('error');
|
||||
setMessage(t('APPS_MESSAGES_MESSAGE_GROUP_CREATE_MINE'));
|
||||
} else if (error) {
|
||||
setOpen(true);
|
||||
setSeverity('error');
|
||||
setMessage(t('APPS_MESSAGES_MESSAGE_GROUP_CREATE_FAILED'));
|
||||
}
|
||||
}, [alert, t]);
|
||||
|
||||
return (
|
||||
<Snackbar
|
||||
autoHideDuration={ALERT_TIMEOUT}
|
||||
className={classes.root}
|
||||
open={open}
|
||||
onClose={handleClose}
|
||||
>
|
||||
<Alert onClose={handleClose} severity={severity}>
|
||||
{message}
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { CreateMessageGroupResult } from '../../../common/typings/messages';
|
||||
|
||||
import { messageState } from './state';
|
||||
|
||||
interface IUseAlerts {
|
||||
createMessageGroupResult: CreateMessageGroupResult | null;
|
||||
}
|
||||
|
||||
export default (): IUseAlerts => {
|
||||
const createMessageGroupResult = useRecoilValue<CreateMessageGroupResult | null>(
|
||||
messageState.createMessageGroupResult
|
||||
);
|
||||
|
||||
return { createMessageGroupResult };
|
||||
};
|
||||
@@ -413,20 +413,46 @@ onNet(
|
||||
);
|
||||
|
||||
if (result.error) {
|
||||
emitNet(
|
||||
events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED,
|
||||
_source,
|
||||
result
|
||||
);
|
||||
// if it just fails, welp
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source, result);
|
||||
/*emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`,
|
||||
type: 'error',
|
||||
});*/
|
||||
|
||||
console.log(result);
|
||||
|
||||
// if you try to create a existing group
|
||||
} else if (result.error && result.duplicate) {
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_MESSAGE_GROUP_DUPLICATE',
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
// if the phoneNumber is invalid
|
||||
} else if (result.error && result.phoneNumber) {
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_INVALID_PHONE_NUMBER' + result.phoneNumber,
|
||||
type: 'error',
|
||||
});
|
||||
|
||||
// if you are try to add yourself
|
||||
} else if (result.error && result.mine) {
|
||||
console.log('yes');
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_MESSAGE_GROUP_CREATE_MINE',
|
||||
type: 'error',
|
||||
});
|
||||
} else {
|
||||
emitNet(
|
||||
events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS,
|
||||
_source,
|
||||
result
|
||||
);
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, _source, result);
|
||||
}
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source);
|
||||
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`,
|
||||
type: 'error',
|
||||
});
|
||||
messageLogger.error(`Failed to create message group, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
@@ -457,7 +483,16 @@ onNet(
|
||||
await createMessage(_identifier, groupId, message);
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, _source, groupId);
|
||||
} catch (e) {
|
||||
// Not really sure what this does? As I cant find any reference
|
||||
// of this in the ui part.
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_FAILED, _source);
|
||||
// sending a new alert
|
||||
// The message property is always using the locale strings without
|
||||
// the APPS_ prefix.
|
||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||
message: 'MESSAGES_NEW_MESSAGE_FAILED',
|
||||
type: 'error',
|
||||
});
|
||||
messageLogger.error(`Failed to send message, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user