# CustomTaskForm

Drawer form for creating and editing basic (non-survey) task actions within an Employee Lifecycle process step. Action type is `TASK`.

## File structure

```
CustomTaskForm/
├── index.tsx          # Re-exports: { CustomTaskForm } from './form', default from './provider'
├── provider.tsx       # Data loading: useGetFormDefaultValues → renders CustomTaskForm
├── form.tsx           # Form shell: useForm, Drawer chrome (Header/Body/Actions), submit/cancel logic
├── content.tsx        # Pure field sections (no Drawer.* components); consumes form context
├── types.ts           # TypeScript types for form values, props, internal types (JSDoc documented)
├── schemas.ts         # Zod schema: createCustomTaskFormSchema (delegates to shared base + refinements)
├── fields.ts          # Field configuration generator (getCustomTaskFormFields)
├── constants.ts       # Field name map (customTaskFields)
├── utils.ts           # getDefaultValues (delegates to shared getBaseTaskDefaultValues)
├── validations.ts     # applyCustomTaskFormRefinements + validation constants (min/max values)
└── components/
    ├── AssigneeAutocomplete/   # Autocomplete for selecting task assignee
    ├── IconSelectButton/       # Button to open icon picker
    └── TaskListAutocomplete/   # Autocomplete for task list selection
```

## Usage

Default export is the Provider (handles data loading). Use it when opening from a drawer layer.

```tsx
import CustomTaskFormProvider from './CustomTaskForm';

// Create
<CustomTaskFormProvider processId={processId} stepId={stepId} />

// Edit
<CustomTaskFormProvider processId={processId} stepId={stepId} actionId={actionId} />
```

Named export `CustomTaskForm` (from `form.tsx`) can be used when `defaultValues` are already available (e.g. in tests or a custom provider).

## Form sections (content.tsx)

All sections come from `../shared/`:

| Section | Shared component | Key fields |
|---|---|---|
| Cover image | `CoverImageSection` | `hasCoverImage`, `coverImage` |
| Icon + name | `IconNameSection` | `icon`, `name` |
| Assignee + description | `AssigneeDescriptionSection` | `assignee`, `description` |
| Attachments | `AttachmentsSection` | `hasAttachments`, `attachments` |
| Due date | `DueDateSection` | `hasDueDate`, `expiresAfter` |
| Reminders | `ReminderSection` | `hasReminder`, `remindOnDueDay`, `repeatReminder`, `reminderFrequency`, `reminderFrequencyType`, `reminderChannels` |
| Dependency | `DependencySection` | `hasDependency`, `dependsOn` |

## Validation (validations.ts + schemas.ts)

`createCustomTaskFormSchema` wraps the shared base schema with `applyCustomTaskFormRefinements`, which adds cross-field rules:

- **Cover image**: required when `hasCoverImage` is true
- **Attachments**: required when `hasAttachments` is true
- **Due date**: `expiresAfter` required and must be an integer between 1–365 when `hasDueDate` is true
- **Reminders**: at least one of `remindOnDueDay` or `repeatReminder` required when `hasReminder` is true; when `repeatReminder` is true, `reminderFrequency` (1–1000, integer) and `reminderFrequencyType` are also required; `reminderChannels` always required when reminders are on
- **Dependency**: `dependsOn` required when `hasDependency` is true

## Provider data flow

```
CustomTaskFormProvider (provider.tsx)
  └── useGetFormDefaultValues({ processId, stepId, actionId, getDefaultValuesFn })
        │
        ▼
  CustomTaskForm (form.tsx)
  ├── useForm({ defaultValues, resolver: zodResolver(createCustomTaskFormSchema) })
  ├── CustomTaskFormContent (content.tsx)  ← field sections
  └── onSubmit → convertFormValuesToStepAction → updateOrCreateCustomTaskAction
```

## Related

- `../shared/` — shared field sections, hooks (`useTaskFormSubmit`, `useConfirmChangesModal`), transforms, base schema
- `../SurveyConfigForm/` — same structure extended with Survey Builder integration
- `../../../../../../types.ts` — `ActionType`, `CustomTaskType`

---

> Update this file when the module structure, form sections, or validation rules change.
