# Todoist Task Creation

## Objective

Let a user send any app record to their own Todoist with project, label, and due date.

A per-user Todoist connection and a send action that creates a personal task carrying a link back to the source record.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Make this a per-user connection, not a workspace one. The task lands in that person's own account, so the authorisation, the project list, and the disconnect control all belong on their account settings.
2. Add a send action to the record types a person would realistically want on a personal list, and let them choose the project, label, priority, and due date at send time with their last choice remembered as the default.
3. Send an explicit date or timestamp for the due date, resolved in the user's own time zone before it leaves the app. Do not pass through a phrase like tomorrow and rely on the provider parsing it, because the parse depends on a locale and a clock you do not control.
4. Include a link back to the source record in every task, so the person reading it a week later can get to the thing it refers to.
5. Store the created task identifier against the source record and the user, so a repeat send updates or refuses rather than stacking duplicates, and so the app can show that this record has already been sent.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Natural-language due dates are interpreted by the provider against a time zone and a reference clock the app does not own, which turns a local deadline into the wrong day. Resolve to an explicit timestamp in the user's time zone first.
- A project or label chosen months ago can be archived, renamed, or deleted. Re-check the target before sending, and prompt the user to pick again instead of dropping the task into the default inbox without saying so.
- A retried send after a network timeout produces two identical tasks. Guard creation with a stable key derived from the record and the user, and reconcile against the stored task identifier.
- A backlink pointing at a record the recipient cannot open is useless. Link to the canonical record URL and let the app's own access rules handle the rest.
- Personal projects can be shared with other people. Do not put customer names, internal notes, or private context into the task body by default; put the summary in the task and keep the detail behind the backlink.
- The user's authorisation expires or is revoked from Todoist without warning. Detect the failure, mark the connection as disconnected on their settings screen, and stop retrying.
- A person sending several records in a row will hit the rate limit. Queue the sends, back off on the provider's signal, and show each task as pending until it is confirmed.
- When Todoist is unavailable the send must fail visibly and recoverably. Tell the user it did not go through and let them retry, rather than showing a success that never happened.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Each user connects and disconnects their own Todoist account from their account settings.
- [ ] Due dates arrive as explicit timestamps resolved in the user's time zone, with no reliance on provider-side parsing.
- [ ] A missing, archived, or renamed project or label prompts the user rather than silently redirecting the task.
- [ ] Sending the same record twice does not create two tasks, and the app shows that the record was already sent.
- [ ] Every created task contains a working link back to the source record.
- [ ] An expired or revoked connection is surfaced on the user's settings screen and stops further retries.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
