# useDocyrusLogActivity URL: /docs/native/hooks/use-docyrus-log-activity Docyrus data engine for LogActivityForm. Fetches comments, users, task and event options and the record's status field, and runs the comment, task, event and two-call status mutations. ## Installation ```bash pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-log-activity ``` **Dependencies:** - [@tanstack/react-query](https://www.npmjs.com/package/@tanstack/react-query) - [@docyrus/api-client](https://www.npmjs.com/package/@docyrus/api-client) The hook owns all network I/O for the presentational [rn-log-activity-form](/docs/native/docyrus/log-activity-form) and returns a `logActivityProps` bag to spread onto it. It needs a `QueryClientProvider` above it. ## Usage ```tsx import { useDocyrusClient } from '@docyrus/signin/react-native'; import { LogActivityForm } from '@/components/docyrus-native/log-activity-form'; import { useDocyrusLogActivity } from '@/hooks/docyrus-native/use-docyrus-log-activity'; export function ContactLogActivity({ contactId, meId }: { contactId: string; meId: string }) { const client = useDocyrusClient(); const { logActivityProps } = useDocyrusLogActivity({ client, appSlug: 'base', dataSourceSlug: 'contact', recordId: contactId, relationSlug: 'contact', currentUserId: meId, callEventTypeName: 'Call', meetingEventTypeName: 'Meeting' }); return ; } ``` ### What it calls | Tab | Requests | |-----|----------| | Comment | `GET {record}/comments`, `POST {record}/comments`, `DELETE {record}/comments/:id`, users from `/v1/users` | | Task | `GET /v1/apps/{taskApp}/data-sources/{taskDs}?expand=fields,enums` (status + priority enums), `POST …/{taskDs}/items` linked through `taskRelationSlug ?? relationSlug` | | Call / Meeting | `GET /v1/apps/{eventTypeApp}/data-sources/{eventTypeDs}/items` (event types), `POST /v1/apps/{eventApp}/data-sources/{eventDs}/items` linked through `eventRelationSlug ?? relationSlug` | | Status | `GET {dataSource}?expand=fields,enums` (status field), `GET {record}?columns=…` (current value), then `PATCH {record}` followed by `POST {dataSource}/status-update/:slug` | `{record}` is `/v1/apps/:appSlug/data-sources/:dataSourceSlug/items/:recordId`. Queries for tabs that are not in `activityTypes` never run. If the `PATCH` succeeds but logging the status update fails, the mutation rejects with an error carrying `partial: true`. The status was still changed. Every successful mutation invalidates the record-scoped `['docyrus-contact-activity', {record}]` prefix. A mounted [`useDocyrusContactActivity`](/docs/native/hooks/use-docyrus-contact-activity) timeline for the same record refreshes automatically. ### Email tab Like web, the hook embeds [`useDocyrusEmailComposer`](/docs/native/hooks/use-docyrus-email-composer): sender accounts, `@` mention users and the send mutation, with recipients seeded from `emailTo`. Its queries only run while the `email` tab is enabled. Native-only: pass `emailComposerProps`, `onSendEmail` and `isSendingEmail` to replace it with your own email wiring. The embedded composer then stays idle. ## API Reference ### UseDocyrusLogActivityOptions | Option | Type | Default | Description | |--------|------|---------|-------------| | `client` | `RestApiClient` | - | Authenticated Docyrus REST client (required) | | `appSlug` | `string` | - | Owning record's app (required) | | `dataSourceSlug` | `string` | - | Owning record's data source (required) | | `recordId` | `string` | - | Owning record id (required). Queries wait until it is set | | `relationSlug` | `string` | - | Back-relation slug linking new tasks and events to the record | | `eventRelationSlug` | `string` | `relationSlug` | Event back-relation override | | `taskRelationSlug` | `string` | `relationSlug` | Task back-relation override | | `statusFieldSlug` | `string` | first `field-status` | Status field on the record's data source | | `activityTypes` | `LoggableActivityType[]` | all six | Tabs shown. Also gates the queries | | `taskAppSlug` | `string` | `'base'` | Tasks app | | `taskDataSourceSlug` | `string` | `'task'` | Tasks data source | | `taskStatusFieldSlug` | `string` | `'status'` | Task status field | | `taskPriorityFieldSlug` | `string` | `'priority'` | Task priority field | | `eventAppSlug` | `string` | `'base'` | Events app | | `eventDataSourceSlug` | `string` | `'event'` | Events data source | | `eventTypeAppSlug` | `string` | `'base'` | Event type (calendar) app | | `eventTypeDataSourceSlug` | `string` | `'calendar'` | Event type (calendar) data source | | `callEventTypeId` | `string` | - | Preset event type for Call | | `meetingEventTypeId` | `string` | - | Preset event type for Meeting | | `callEventTypeName` | `string` | - | Resolve the Call event type by name (case-insensitive) when no id is given | | `meetingEventTypeName` | `string` | - | Resolve the Meeting event type by name when no id is given | | `users` | `CommentUser[]` | - | Users to use instead of fetching `/v1/users` | | `currentUserId` | `string` | - | Current user id (own comments) | | `usersLimit` | `number` | `1000` | Max users fetched | | `listUsersEndpoint` | `string` | `'/v1/users'` | Users endpoint override | | `emailTo` | `string[]` | - | Seed the Email tab recipients | | `emailComposerProps` | `Partial` | - | Native-only: overrides the embedded `useDocyrusEmailComposer` props | | `onSendEmail` | `() => void \| Promise` | - | Native-only: overrides the embedded send | | `isSendingEmail` | `boolean` | `false` | Native-only: pending send state when you override the email wiring | | `enabled` | `boolean` | `true` | Toggle every query | ### UseDocyrusLogActivityResult | Field | Type | Description | |-------|------|-------------| | `logActivityProps` | `DocyrusLogActivityProps` | Spread onto `` | | `createComment` | `(payload: LogActivityCommentPayload) => Promise` | Post a comment or reply | | `deleteComment` | `(commentId: string) => Promise` | Delete a comment | | `createTask` | `(input: LogTaskInput) => Promise` | Create a linked task | | `createEvent` | `(input: LogEventInput, kind: 'call' \| 'meeting') => Promise` | Create a linked event | | `updateStatus` | `(input: LogStatusInput) => Promise` | Two-call status change | | `isCreatingComment` | `boolean` | Comment mutation pending | | `isCreatingTask` | `boolean` | Task mutation pending | | `isCreatingEvent` | `boolean` | Event mutation pending | | `isUpdatingStatus` | `boolean` | Status mutation pending | | `refetch` | `() => Promise` | Invalidate the record-scoped activity cache | ## Type Exports | Type | Description | |------|-------------| | `UseDocyrusLogActivityOptions` | Hook options | | `UseDocyrusLogActivityResult` | Hook result | | `DocyrusLogActivityProps` | The subset of `LogActivityFormProps` the hook fills |