Skip to content

Commit 7e660cb

Browse files
committed
Fix whitespace-only company names and stale search results
- Validate trimmed company name with min length in upsert-company action - Clear company list and select results when search term changes
1 parent a4c9a8a commit 7e660cb

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

apps/cursor/src/actions/upsert-company.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export const upsertCompanyAction = authActionClient
1616
.schema(
1717
z.object({
1818
id: z.string().optional(),
19-
name: z.string(),
19+
name: z
20+
.string()
21+
.trim()
22+
.min(2, { message: "Name must be at least 2 characters." }),
2023
image: z.string().url().nullable(),
2124
slug: z.string().optional(),
2225
location: z.string().nullable(),
@@ -31,7 +34,7 @@ export const upsertCompanyAction = authActionClient
3134
async ({
3235
parsedInput: {
3336
id,
34-
name: rawName,
37+
name,
3538
image,
3639
slug,
3740
location,
@@ -45,7 +48,6 @@ export const upsertCompanyAction = authActionClient
4548
}) => {
4649
const supabase = await createClient();
4750

48-
const name = rawName.trim();
4951
const nameKey = name.toLowerCase();
5052

5153
// Only treat the request as an edit when a row with the provided id

apps/cursor/src/components/company/company-list.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function CompanyList({ data }: { data?: Company[] | null }) {
2323

2424
// With a search term, query the entire companies table rather than
2525
// filtering only the rows that happen to be loaded on the page.
26+
setCompanies([]);
2627
let active = true;
2728
const handle = setTimeout(async () => {
2829
const results = await searchCompanies(term);

apps/cursor/src/components/company/company-select.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export function CompanySelect({
143143
return;
144144
}
145145

146+
setResults([]);
146147
let active = true;
147148
setLoading(true);
148149

0 commit comments

Comments
 (0)