Skip to content

Commit 6a6a5ca

Browse files
authored
Merge pull request #1499 from stakwork/refactor/allow-freetext-in-url-validation-1750410223
Refactor URL validation to allow freetext input in ManageCodeSpaceModal.tsx
2 parents 43e08ac + 600b81b commit 6a6a5ca

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/people/widgetViews/workspace/ManageCodeSpaceModal.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ const ManageCodeSpaceModal: React.FC<CodeSpaceProps> = ({
114114
}
115115
};
116116

117+
const isValidCodeSpaceInput = (input: string) => {
118+
// Allow both URLs and freetext entries (e.g., 'hive', 'tribes')
119+
// Return true for any non-empty string
120+
return input.trim().length > 0;
121+
};
122+
117123
useEffect(() => {
118124
const fetchCodeSpace = async () => {
119125
try {
@@ -123,7 +129,7 @@ const ManageCodeSpaceModal: React.FC<CodeSpaceProps> = ({
123129
setCodeSpace(response);
124130
setGithubPat(response.githubPat || ''); // Initialize PAT state
125131
setBaseBranch(response.baseBranch || ''); // Initialize Base Branch state
126-
setUrlError(!isValidUrl(response.codeSpaceURL)); // Also validate fetched URL
132+
setUrlError(!isValidCodeSpaceInput(response.codeSpaceURL)); // Also validate fetched input
127133
} else {
128134
// Initialize state for creating a new code space
129135
setCodeSpace({
@@ -176,7 +182,7 @@ const ManageCodeSpaceModal: React.FC<CodeSpaceProps> = ({
176182
if (!codeSpace) return;
177183
const newUrl = e.target.value;
178184
setCodeSpace({ ...codeSpace, codeSpaceURL: newUrl });
179-
setUrlError(!isValidUrl(newUrl));
185+
setUrlError(!isValidCodeSpaceInput(newUrl));
180186
};
181187

182188
const handlePatChange = (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -188,7 +194,7 @@ const ManageCodeSpaceModal: React.FC<CodeSpaceProps> = ({
188194
};
189195

190196
const handleSave = async () => {
191-
if (!codeSpace || !isValidUrl(codeSpace.codeSpaceURL)) return;
197+
if (!codeSpace || !isValidCodeSpaceInput(codeSpace.codeSpaceURL)) return;
192198

193199
setIsLoading(true);
194200
try {
@@ -278,7 +284,7 @@ const ManageCodeSpaceModal: React.FC<CodeSpaceProps> = ({
278284
</Wrapper>
279285
{urlError && (
280286
<p style={{ color: 'red', fontSize: '12px', marginLeft: '33%' }}>
281-
Invalid URL. Ensure it starts with https://
287+
Enter a valid codespace url or pool name.
282288
</p>
283289
)}
284290
<ButtonGroup>

0 commit comments

Comments
 (0)