mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 16:51:42 +03:00
ux: inform user when session input is invalid
Show a helpful error message via `alert` instead of failing silently.
This commit is contained in:
parent
0d2c135959
commit
6256a0a664
@ -18,6 +18,7 @@ export const useAddSession = () => {
|
||||
const userInput = prompt('Please enter an alpha-numeric session name.');
|
||||
// user canceled or did not enter a value
|
||||
if (!userInput) {
|
||||
alert('A valid name is required to create a new session');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -25,6 +26,7 @@ export const useAddSession = () => {
|
||||
if (AGENT_SESSION_REGEX.test(userInput)) {
|
||||
const match = AGENT_SESSION_REGEX.exec(userInput);
|
||||
if (!match) {
|
||||
alert('Invalid format. Valid syntax: agent!session-name');
|
||||
return;
|
||||
}
|
||||
agent = match[1];
|
||||
@ -33,15 +35,18 @@ export const useAddSession = () => {
|
||||
} else if (SESSION_ID_REGEX.test(userInput)) {
|
||||
const match = SESSION_ID_REGEX.exec(userInput);
|
||||
if (!match) {
|
||||
alert('Invalid format. Valid syntax: session-name');
|
||||
return;
|
||||
}
|
||||
sessionName = match[1];
|
||||
} else {
|
||||
alert('Invalid format. Valid syntax: session-name');
|
||||
return;
|
||||
}
|
||||
|
||||
// avoid nil or duplicate sessions
|
||||
if(!sessionName || names.includes(sessionName)) {
|
||||
// prevent duplicate sessions
|
||||
if(names.includes(sessionName)) {
|
||||
alert(`Session name must be unique ("${sessionName}" already in use)`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user