mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
more error handling
This commit is contained in:
1 parent
9403edcb92
commit
2c4c54109f
9 files changed
+101
-23
No files matched your search
@@ -10,7 +10,7 @@ const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
width: "100%",
|
||||
bottom: "60px",
|
||||
position: 'absolute',
|
||||
position: "absolute",
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -19,25 +19,32 @@ const ALERT_TIMEOUT = 6000;
|
||||
export default function AlertBar() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { createMessageGroupResult, setCreateMessageGroupResult } = useAlerts();
|
||||
const {
|
||||
createMessageGroupResult,
|
||||
clearCreateMessageGroupResult,
|
||||
} = useAlerts();
|
||||
const [severity, setSeverity] = useState<string | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
|
||||
const handleClose = () => {
|
||||
setOpen(false);
|
||||
setCreateMessageGroupResult(null);
|
||||
clearCreateMessageGroupResult();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!createMessageGroupResult) return;
|
||||
|
||||
const { error, phoneNumber } = createMessageGroupResult
|
||||
const { error, phoneNumber, duplicate } = createMessageGroupResult;
|
||||
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) {
|
||||
setOpen(true);
|
||||
setSeverity("error");
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { useRecoilState } from "recoil";
|
||||
import { CreateMessageGroupResult } from "../../../common/interfaces/messages";
|
||||
|
||||
import { messageState } from './state';
|
||||
import { messageState } from "./state";
|
||||
|
||||
interface IUseAlerts {
|
||||
createMessageGroupResult: any;
|
||||
setCreateMessageGroupResult: any;
|
||||
createMessageGroupResult: CreateMessageGroupResult | null;
|
||||
clearCreateMessageGroupResult: () => void;
|
||||
}
|
||||
|
||||
export default (): IUseAlerts => {
|
||||
const [createMessageGroupResult, setCreateMessageGroupResult] = useRecoilState<any>(messageState.createMessageGroupResult)
|
||||
return { createMessageGroupResult, setCreateMessageGroupResult };
|
||||
}
|
||||
const [
|
||||
createMessageGroupResult,
|
||||
setCreateMessageGroupResult,
|
||||
] = useRecoilState<CreateMessageGroupResult | null>(
|
||||
messageState.createMessageGroupResult
|
||||
);
|
||||
|
||||
const clearCreateMessageGroupResult = () => setCreateMessageGroupResult(null);
|
||||
return { createMessageGroupResult, clearCreateMessageGroupResult };
|
||||
};
|
||||
@@ -17,3 +17,10 @@ export interface MessageGroup {
|
||||
label?: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface CreateMessageGroupResult {
|
||||
error?: boolean;
|
||||
phoneNumber?: string;
|
||||
duplicate?: boolean;
|
||||
groupId?: string;
|
||||
}
|
||||
@@ -58,6 +58,7 @@
|
||||
"APPS_MESSAGES_GROUP_CHAT_LABEL": "Group chat label...",
|
||||
"APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT": "Submit",
|
||||
"APPS_MESSAGES_INVALID_PHONE_NUMBER": "Invalid phone number: ",
|
||||
"APPS_MESSAGES_MESSAGE_GROUP_DUPLICATE": "This message group already exists",
|
||||
"APPS_MESSAGES_MESSAGE_GROUP_CREATE_FAILED": "Failed to create message group"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user