ux: inform user when session input is invalid

Show a helpful error message via `alert` instead of failing silently.
This commit is contained in:
tomholford 2022-03-15 11:16:44 -06:00
parent 0d2c135959
commit 6256a0a664

View File

@ -18,6 +18,7 @@ export const useAddSession = () => {
const userInput = prompt('Please enter an alpha-numeric session name.'); const userInput = prompt('Please enter an alpha-numeric session name.');
// user canceled or did not enter a value // user canceled or did not enter a value
if (!userInput) { if (!userInput) {
alert('A valid name is required to create a new session');
return; return;
} }
@ -25,6 +26,7 @@ export const useAddSession = () => {
if (AGENT_SESSION_REGEX.test(userInput)) { if (AGENT_SESSION_REGEX.test(userInput)) {
const match = AGENT_SESSION_REGEX.exec(userInput); const match = AGENT_SESSION_REGEX.exec(userInput);
if (!match) { if (!match) {
alert('Invalid format. Valid syntax: agent!session-name');
return; return;
} }
agent = match[1]; agent = match[1];
@ -33,15 +35,18 @@ export const useAddSession = () => {
} else if (SESSION_ID_REGEX.test(userInput)) { } else if (SESSION_ID_REGEX.test(userInput)) {
const match = SESSION_ID_REGEX.exec(userInput); const match = SESSION_ID_REGEX.exec(userInput);
if (!match) { if (!match) {
alert('Invalid format. Valid syntax: session-name');
return; return;
} }
sessionName = match[1]; sessionName = match[1];
} else { } else {
alert('Invalid format. Valid syntax: session-name');
return; return;
} }
// avoid nil or duplicate sessions // prevent duplicate sessions
if(!sessionName || names.includes(sessionName)) { if(names.includes(sessionName)) {
alert(`Session name must be unique ("${sessionName}" already in use)`);
return; return;
} }