Date Time Activity
This activity requests the user to select a date, time, or both.
It can be used for scenarios like scheduling an appointment, picking a deadline, or selecting an event date.
Inputs
The DateTimeActivity
expects the following input options:
- Title (
string
): The title that describes what date and time input is required (e.g., "Select Appointment Date"). - Description (
string
): Additional context or details for the user about the date and time selection (optional). - ButtonCancelText (
string
): The label for the button to cancel the activity (e.g., "Cancel"). - ButtonOKText (
string
): The label for the button to confirm the selected date and time (e.g., "Confirm"). - Type (
string
): Defines whether the activity should prompt for adate
,time
, ordatetime
.
Example Code
dateTimeActivity: async (data: DateTimeActivityOptions) => {
console.log('DateTimeActivity from agent:', data);
return new Promise<{ action: WorkflowActivityUserAction; result: string }>((resolve) => {
RootNavigation.navigate('WorkflowActivityScreen', {
type: 'dateTime',
data,
onReject: () => {
console.log('DateTimeActivity result:', 'Rejected');
resolve({
action: WorkflowActivityUserAction.Cancel,
result: '',
});
},
onConfirm: (result: string) => {
console.log('DateTimeActivity result:', result);
resolve({
action: WorkflowActivityUserAction.OK,
result,
});
},
});
});
}
Handling and Layout
When the user navigates to the WorkflowActivityScreen
for a DateTimeActivity
, the layout includes:
-
Title: Displayed as the primary heading to indicate what date/time input is required.
-
Description: Provides context or instructions for the date and time selection.
-
Date and Time Picker:
- For iOS, two separate pickers are displayed for date and time.
- For Android, a touchable component triggers pickers for both date and time. Depending on the platform, a picker for
date
,time
, ordatetime
is shown.
-
Action Buttons:
- Cancel Button: Allows the user to cancel the date and time selection, returning a
Cancel
action. - OK Button: Submits the user’s selection and returns an
OK
action.
- Cancel Button: Allows the user to cancel the date and time selection, returning a
Output
The output for a Date Time Activity depends on the type of selection requested:
- If the user confirms, the resolved result will look like this:
{
action: WorkflowActivityUserAction.OK,
result: "2024-10-23T14:30:00Z", // Example: ISO formatted date and time string
}
- If the user cancels, the resolved result will look like this:
{
action: WorkflowActivityUserAction.Cancel,
result: "",
}