Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function AuthorsSection() {
onChange={(newAuthors) => setValue('authors', newAuthors, { shouldValidate: true })}
placeholder="Search for authors..."
error={getFieldErrorMessage(errors.authors, 'Invalid authors')}
searchType="author"
/>
</div>
);
Expand Down
12 changes: 8 additions & 4 deletions components/Notebook/PublishingForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,15 @@ const autoAddCurrentUser = (

if (getValues(field).length === 0) {
const profile = currentUser.authorProfile;
const authorId = profile?.id?.toString();

if (!isGrant && !authorId) {
return;
}

setValue(field, [
{
value: isGrant
? currentUser.id.toString()
: profile?.id?.toString() || currentUser.id.toString(),
value: isGrant ? currentUser.id.toString() : authorId!,
label: currentUser.fullName || currentUser.email || 'Unknown User',
},
]);
Expand Down Expand Up @@ -472,7 +476,7 @@ export function PublishingForm({
const fallback = 'Error publishing. Please try again.';
if (error instanceof ApiError) {
const errorData = error.errors as Record<string, any> | undefined;
toast.error(errorData?.msg || errorData?.message || fallback);
toast.error(errorData?.msg || errorData?.message || error.message || fallback);
} else {
toast.error(fallback);
}
Expand Down
25 changes: 23 additions & 2 deletions components/ui/form/SearchableUserSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react';
import { SearchableMultiSelect, MultiSelectOption } from './SearchableMultiSelect';
import { SearchService } from '@/services/search.service';
import { UserSuggestion } from '@/types/search';
import { AuthorSuggestion, UserSuggestion } from '@/types/search';
import { Avatar } from '@/components/ui/Avatar';
import { VerifiedBadge } from '@/components/ui/VerifiedBadge';
import { Button } from '@/components/ui/Button';
Expand Down Expand Up @@ -62,6 +62,7 @@ export interface SearchableUserSelectProps {
helperText?: string;
debounceMs?: number;
getOptionValue?: (user: UserSuggestion) => string;
searchType?: 'user' | 'author';
}

export function SearchableUserSelect({
Expand All @@ -72,9 +73,29 @@ export function SearchableUserSelect({
helperText,
debounceMs = 300,
getOptionValue = defaultGetOptionValue,
searchType = 'user',
}: Readonly<SearchableUserSelectProps>) {
const handleAsyncSearch = useCallback(
async (query: string) => {
if (searchType === 'author') {
const suggestions = await SearchService.suggestPeople(query);

return suggestions
.filter((author): author is AuthorSuggestion & { id: NonNullable<AuthorSuggestion['id']> } =>
Boolean(author.id)
)
.map((author) => ({
value: author.id.toString(),
label: author.fullName || 'Unknown Author',
avatarUrl: author.profileImage,
description: author.headline,
profileUrl:
typeof author.id === 'number' || typeof author.id === 'string'
? buildAuthorUrl(author.id)
: undefined,
}));
}

const suggestions = await SearchService.getSuggestions(query, 'user');

return suggestions
Expand All @@ -91,7 +112,7 @@ export function SearchableUserSelect({
profileUrl: user.authorProfile?.id ? buildAuthorUrl(user.authorProfile.id) : undefined,
}));
},
[getOptionValue]
[getOptionValue, searchType]
);

return (
Expand Down