-
Notifications
You must be signed in to change notification settings - Fork 344
feat(activity-feed-v2): add TaskFormV2 with blueprint primitives and user-selector #4662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/elements/content-sidebar/activity-feed-v2/task-modal-v2/TaskFormV2.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .bcs-NewTaskForm { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--bp-space-040); | ||
|
|
||
| // Allow direct children to shrink below their content's intrinsic width so | ||
| // the user-selector chips wrap inside the modal instead of widening it. | ||
| > * { | ||
| min-width: 0; | ||
| } | ||
| } |
195 changes: 195 additions & 0 deletions
195
src/elements/content-sidebar/activity-feed-v2/task-modal-v2/TaskFormV2.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| import * as React from 'react'; | ||
| import { useIntl } from 'react-intl'; | ||
|
|
||
| import { Checkbox, DatePicker, TextArea } from '@box/blueprint-web'; | ||
| import { UserSelectorContainer } from '@box/user-selector'; | ||
| import type { FetchedAvatarUrls, UserContactType } from '@box/user-selector'; | ||
| import type { DateValue } from 'react-aria-components'; | ||
| import { fromDate, getLocalTimeZone, today } from '@internationalized/date'; | ||
|
|
||
| import { TASK_COMPLETION_RULE_ALL, TASK_COMPLETION_RULE_ANY, TASK_EDIT_MODE_EDIT } from '../../../../constants'; | ||
|
|
||
| import type { TaskCompletionRule, TaskEditMode, TaskType } from '../../../../common/types/tasks'; | ||
|
|
||
| import { mapAssigneeToUserContact, mapUserContactToAssignee, type RuntimeAssignee } from './utils/contactMapping'; | ||
|
|
||
| import messages from './messages'; | ||
|
|
||
| import './TaskFormV2.scss'; | ||
|
|
||
| export const TASK_FORM_V2_ID = 'task-form-v2'; | ||
|
|
||
| export type TaskFormV2SubmitPayload = { | ||
| assignees: RuntimeAssignee[]; | ||
| completionRule: TaskCompletionRule; | ||
| dueDate: Date | null; | ||
| message: string; | ||
| }; | ||
|
|
||
| export type TaskFormV2Props = { | ||
| editMode?: TaskEditMode; | ||
| fetchAvatarUrls: (contacts: UserContactType[]) => Promise<FetchedAvatarUrls>; | ||
| fetchUsers: (query: string) => Promise<UserContactType[]>; | ||
| initialAssignees?: RuntimeAssignee[]; | ||
| initialCompletionRule?: TaskCompletionRule; | ||
| initialDueDate?: Date | null; | ||
| initialMessage?: string; | ||
| isDisabled?: boolean; | ||
| onSubmit: (payload: TaskFormV2SubmitPayload) => void | Promise<void>; | ||
| taskType: TaskType; | ||
| }; | ||
|
|
||
| // Backend treats dueDate as inclusive end-of-day for new tasks; existing tasks | ||
| // keep their original time so edit-mode round-trips do not silently retime. | ||
| const toSubmitDate = ( | ||
| value: DateValue, | ||
| originalTime: { hours: number; minutes: number; seconds: number; ms: number } | null, | ||
| ): Date => { | ||
| const date = value.toDate(getLocalTimeZone()); | ||
| if (originalTime) { | ||
| date.setHours(originalTime.hours, originalTime.minutes, originalTime.seconds, originalTime.ms); | ||
| } else { | ||
| date.setHours(23, 59, 59, 999); | ||
| } | ||
| return date; | ||
| }; | ||
|
|
||
| const captureTime = (date: Date | null) => | ||
| date | ||
| ? { | ||
| hours: date.getHours(), | ||
| minutes: date.getMinutes(), | ||
| seconds: date.getSeconds(), | ||
| ms: date.getMilliseconds(), | ||
| } | ||
| : null; | ||
|
|
||
| const TaskFormV2 = ({ | ||
| editMode, | ||
| fetchAvatarUrls, | ||
| fetchUsers, | ||
| initialAssignees = [], | ||
| initialCompletionRule = TASK_COMPLETION_RULE_ALL, | ||
| initialDueDate = null, | ||
| initialMessage = '', | ||
| isDisabled = false, | ||
| onSubmit, | ||
| taskType, | ||
| }: TaskFormV2Props) => { | ||
| const { formatMessage } = useIntl(); | ||
| const isEditMode = editMode === TASK_EDIT_MODE_EDIT; | ||
|
|
||
| const [formElement, setFormElement] = React.useState<HTMLFormElement | null>(null); | ||
| const portalElement = React.useCallback(() => formElement ?? document.body, [formElement]); | ||
|
|
||
| const [selectedUsers, setSelectedUsers] = React.useState<UserContactType[]>(() => | ||
| initialAssignees.map(mapAssigneeToUserContact), | ||
| ); | ||
| const [completionRule, setCompletionRule] = React.useState<TaskCompletionRule>(initialCompletionRule); | ||
| const [message, setMessage] = React.useState<string>(initialMessage); | ||
| const [dueDate, setDueDate] = React.useState<DateValue | null>( | ||
| initialDueDate ? fromDate(initialDueDate, getLocalTimeZone()) : null, | ||
| ); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const originalDueDateTime = React.useMemo( | ||
| () => (isEditMode ? captureTime(initialDueDate) : null), | ||
| [isEditMode, initialDueDate], | ||
| ); | ||
| const [hasAttemptedSubmit, setHasAttemptedSubmit] = React.useState<boolean>(false); | ||
|
|
||
| const isGroupSelected = selectedUsers.some(user => user.type === 'group'); | ||
| const userAssigneeCount = selectedUsers.filter(user => user.type === 'user').length; | ||
| const shouldShowCompletionRule = selectedUsers.length > 0; | ||
| const isCompletionRuleDisabled = !isGroupSelected && userAssigneeCount <= 1; | ||
|
|
||
| const messageError = | ||
| hasAttemptedSubmit && message.trim() === '' ? formatMessage(messages.messageFieldRequiredError) : undefined; | ||
| const assigneeError = | ||
| hasAttemptedSubmit && selectedUsers.length === 0 | ||
| ? formatMessage(messages.assigneeFieldRequiredError) | ||
| : undefined; | ||
|
|
||
| const minCalendarDate = React.useMemo(() => { | ||
| const todayDate = today(getLocalTimeZone()); | ||
| if (initialDueDate && initialDueDate < todayDate.toDate(getLocalTimeZone())) { | ||
| return undefined; | ||
| } | ||
| return todayDate; | ||
| }, [initialDueDate]); | ||
|
|
||
| const handleFormSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
| event.preventDefault(); | ||
| if (isDisabled) { | ||
| return; | ||
| } | ||
| setHasAttemptedSubmit(true); | ||
| if (selectedUsers.length === 0 || message.trim() === '') { | ||
| return; | ||
| } | ||
| onSubmit({ | ||
| assignees: selectedUsers.map(mapUserContactToAssignee), | ||
| completionRule, | ||
| dueDate: dueDate ? toSubmitDate(dueDate, originalDueDateTime) : null, | ||
| message, | ||
| }); | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| return ( | ||
| <form | ||
| ref={setFormElement} | ||
| className="bcs-NewTaskForm" | ||
| data-resin-component="taskformv2" | ||
| data-resin-isediting={isEditMode} | ||
| data-resin-tasktype={taskType} | ||
| id={TASK_FORM_V2_ID} | ||
| onSubmit={handleFormSubmit} | ||
| > | ||
| <UserSelectorContainer | ||
| disabled={isDisabled} | ||
| error={assigneeError} | ||
| fetchAvatarUrls={fetchAvatarUrls} | ||
| fetchUsers={fetchUsers} | ||
| label={formatMessage(messages.assigneeSelectorLabel)} | ||
| onSelectedUsersChange={setSelectedUsers} | ||
| placeholder={selectedUsers.length ? '' : formatMessage(messages.assigneePlaceholder)} | ||
| portalElement={portalElement} | ||
| selectedUsers={selectedUsers} | ||
| /> | ||
| {shouldShowCompletionRule && ( | ||
| <Checkbox.Item | ||
| checked={completionRule === TASK_COMPLETION_RULE_ANY} | ||
| disabled={isDisabled || isCompletionRuleDisabled} | ||
| label={formatMessage(messages.completionRuleCheckboxLabel)} | ||
| name="completionRule" | ||
| onCheckedChange={checked => | ||
| setCompletionRule(checked === true ? TASK_COMPLETION_RULE_ANY : TASK_COMPLETION_RULE_ALL) | ||
| } | ||
| value="any" | ||
| /> | ||
| )} | ||
| <TextArea | ||
| disabled={isDisabled} | ||
| error={messageError} | ||
| label={formatMessage(messages.messageLabel)} | ||
| minRows={3} | ||
| name="taskMessage" | ||
| onChange={event => setMessage(event.target.value)} | ||
| placeholder={formatMessage(messages.messagePlaceholder)} | ||
| value={message} | ||
| /> | ||
| <DatePicker | ||
| calendarAriaLabel={formatMessage(messages.datePickerCalendarAriaLabel)} | ||
| clearDatePickerAriaLabel={formatMessage(messages.datePickerClearAriaLabel)} | ||
| isDisabled={isDisabled} | ||
| label={formatMessage(messages.dueDateLabel)} | ||
| minValue={minCalendarDate} | ||
| nextMonthAriaLabel={formatMessage(messages.datePickerNextMonthAriaLabel)} | ||
| onChange={setDueDate} | ||
| openCalendarDropdownAriaLabel={formatMessage(messages.datePickerOpenAriaLabel)} | ||
| previousMonthAriaLabel={formatMessage(messages.datePickerPreviousMonthAriaLabel)} | ||
| value={dueDate} | ||
| /> | ||
| </form> | ||
| ); | ||
| }; | ||
|
|
||
| export default TaskFormV2; | ||
18 changes: 17 additions & 1 deletion
18
src/elements/content-sidebar/activity-feed-v2/task-modal-v2/TaskModalV2.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| .bcs-NewTaskModal { | ||
| // Doubled class raises specificity above Blueprint Modal.Content size="medium" max-width default. | ||
| .bcs-NewTaskModal.bcs-NewTaskModal { | ||
| display: flex; | ||
| flex-direction: column; | ||
| max-width: 480px; | ||
| gap: var(--bp-space-040); | ||
| } | ||
|
|
||
| // Override Blueprint Modal.Body padding-top via doubled-class specificity. | ||
| .bcs-NewTaskModal-body.bcs-NewTaskModal-body { | ||
| position: relative; | ||
| padding-top: 0; | ||
|
|
||
| // Pins the body to the modal's max-width so chip overflow inside the | ||
| // user-selector cannot widen Modal.Content past its 'medium' clamp. | ||
| &::before { | ||
| display: block; | ||
| width: 100vw; | ||
| content: ''; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.