mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
feat: implement recipients autosuggestions (#1923)
This commit is contained in:
@ -0,0 +1,34 @@
|
||||
import { getRecipientSuggestions } from '@documenso/lib/server-only/recipient/get-recipient-suggestions';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
ZGetRecipientSuggestionsRequestSchema,
|
||||
ZGetRecipientSuggestionsResponseSchema,
|
||||
} from './find-recipient-suggestions.types';
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export const findRecipientSuggestionsRoute = authenticatedProcedure
|
||||
.input(ZGetRecipientSuggestionsRequestSchema)
|
||||
.output(ZGetRecipientSuggestionsResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { teamId, user } = ctx;
|
||||
const { query } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
query,
|
||||
},
|
||||
});
|
||||
|
||||
const suggestions = await getRecipientSuggestions({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
query,
|
||||
});
|
||||
|
||||
return {
|
||||
results: suggestions,
|
||||
};
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZGetRecipientSuggestionsRequestSchema = z.object({
|
||||
query: z.string().default(''),
|
||||
});
|
||||
|
||||
export const ZGetRecipientSuggestionsResponseSchema = z.object({
|
||||
results: z.array(
|
||||
z.object({
|
||||
name: z.string().nullable(),
|
||||
email: z.string().email(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export type TGetRecipientSuggestionsRequestSchema = z.infer<
|
||||
typeof ZGetRecipientSuggestionsRequestSchema
|
||||
>;
|
||||
|
||||
export type TGetRecipientSuggestionsResponseSchema = z.infer<
|
||||
typeof ZGetRecipientSuggestionsResponseSchema
|
||||
>;
|
||||
@ -12,6 +12,7 @@ import { updateTemplateRecipients } from '@documenso/lib/server-only/recipient/u
|
||||
|
||||
import { ZGenericSuccessResponse, ZSuccessResponseSchema } from '../document-router/schema';
|
||||
import { authenticatedProcedure, procedure, router } from '../trpc';
|
||||
import { findRecipientSuggestionsRoute } from './find-recipient-suggestions';
|
||||
import {
|
||||
ZCompleteDocumentWithTokenMutationSchema,
|
||||
ZCreateDocumentRecipientRequestSchema,
|
||||
@ -42,6 +43,10 @@ import {
|
||||
} from './schema';
|
||||
|
||||
export const recipientRouter = router({
|
||||
suggestions: {
|
||||
find: findRecipientSuggestionsRoute,
|
||||
},
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user