-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Create button * Move modal to ui-components * Move country selector to features folder * Update country selector exports/imports * Update tupaia-pin.svg * Country selector on modal * Move survey selector to features * Move types * Update survey list component to take care of fetching * Survey selector * Move entity selector to features * Fix types * Entity selector * Styling entity selector * Due date * WIP * WIP * assignee input * Add loading state and save user id * Styling repeat scheduler * Comments placholder * Styling * WIP * Create task route * Create task workflow * Clear form when modal is reopened * Update schemas.ts * remove unused import * Handle reset * Fix datatrak tests * Fix central server tests * Move modal to ui-components * Remove unused import * Remove duplicate file * Fix build * Fix tests * Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js Co-authored-by: Tom Caiger <caigertom@gmail.com> * Fix error messages * Handle search term in the BE * WIP * WIP * Assignee Id modal * Working assignee * remove unused property * Fix timezone issue * Fix date formatting of filter * remove unused variable * Remove unused variable * Fix casing * Default to showing countries if no primary entity question * Update AssigneeInput.tsx * Show loader when loading project and countries * Fix copy * Exclude internal users * Fix types * Change colour of icon in entity list * Link to details page * Fix modal button types * Fix types * Update handling of columns * get task route * WIP * Link to survey for incomplete tasks * Handle unloaded task * Task metadata section * Fix merge issue * WIP * Update schemas.ts * feat(datatrakWeb): RN-1358: Assign tasks from dashboard (#5770) * Create button * Move modal to ui-components * Move country selector to features folder * Update country selector exports/imports * Update tupaia-pin.svg * Country selector on modal * Move survey selector to features * Move types * Update survey list component to take care of fetching * Survey selector * Move entity selector to features * Fix types * Entity selector * Styling entity selector * Due date * WIP * WIP * assignee input * Add loading state and save user id * Styling repeat scheduler * Comments placholder * Styling * WIP * Create task route * Create task workflow * Clear form when modal is reopened * Update schemas.ts * remove unused import * Handle reset * Fix datatrak tests * Fix central server tests * Move modal to ui-components * Remove unused import * Remove duplicate file * Fix build * Fix tests * Update packages/central-server/src/apiV2/utilities/constructNewRecordValidationRules.js Co-authored-by: Tom Caiger <caigertom@gmail.com> * Fix error messages * Handle search term in the BE * WIP * WIP * Assignee Id modal * Working assignee * remove unused property * Fix timezone issue * Fix date formatting of filter * remove unused variable * Remove unused variable * Fix casing * Default to showing countries if no primary entity question * Update AssigneeInput.tsx * Show loader when loading project and countries * Fix copy * Exclude internal users * Fix types * Change colour of icon in entity list * Fix modal button types * Fix types --------- Co-authored-by: Tom Caiger <caigertom@gmail.com> * Fix merge error * Fix styles and types * Styling * Fix multi re-render * Comments placeholder * Add buttons * Submit changes * Clear changes * Fix merge issues * Disable inputs when task is completed or cancelled * responsive styling * Add cancel menu * Generate types * Fix loading styling * Remove unused var * Handle onSuccess of edit task * PR fixes * PR fixes * Remove form provider --------- Co-authored-by: Tom Caiger <caigertom@gmail.com>
- Loading branch information
Showing
45 changed files
with
815 additions
and
417 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,32 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { Request } from 'express'; | ||
import { Route } from '@tupaia/server-boilerplate'; | ||
import { formatTaskChanges } from '../utils'; | ||
import { DatatrakWebTaskChangeRequest } from '@tupaia/types'; | ||
|
||
export type EditTaskRequest = Request< | ||
{ taskId: string }, | ||
Record<string, never>, | ||
Partial<DatatrakWebTaskChangeRequest.ReqBody>, | ||
Record<string, never> | ||
>; | ||
|
||
export class EditTaskRoute extends Route<EditTaskRequest> { | ||
public async buildResponse() { | ||
const { body, ctx, params } = this.req; | ||
|
||
const { taskId } = params; | ||
|
||
const taskDetails = formatTaskChanges(body); | ||
|
||
return ctx.services.central.updateResource(`tasks/${taskId}`, {}, taskDetails); | ||
} | ||
} |
This file contains 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,47 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { Request } from 'express'; | ||
import { Route } from '@tupaia/server-boilerplate'; | ||
import { DatatrakWebTaskRequest } from '@tupaia/types'; | ||
import { TaskT, formatTaskResponse } from '../utils'; | ||
|
||
export type TaskRequest = Request< | ||
DatatrakWebTaskRequest.Params, | ||
DatatrakWebTaskRequest.ResBody, | ||
DatatrakWebTaskRequest.ReqBody, | ||
DatatrakWebTaskRequest.ReqQuery | ||
>; | ||
|
||
const FIELDS = [ | ||
'id', | ||
'survey.name', | ||
'survey.code', | ||
'entity.country_code', | ||
'entity.name', | ||
'assignee_name', | ||
'assignee_id', | ||
'task_status', | ||
'due_date', | ||
'repeat_schedule', | ||
'survey_id', | ||
'entity_id', | ||
]; | ||
|
||
export class TaskRoute extends Route<TaskRequest> { | ||
public async buildResponse() { | ||
const { ctx, params } = this.req; | ||
const { taskId } = params; | ||
|
||
const task: TaskT = await ctx.services.central.fetchResources(`tasks/${taskId}`, { | ||
columns: FIELDS, | ||
}); | ||
if (!task) { | ||
throw new Error(`Task with id ${taskId} not found`); | ||
} | ||
|
||
return formatTaskResponse(task); | ||
} | ||
} |
This file contains 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
This file contains 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
42 changes: 42 additions & 0 deletions
42
packages/datatrak-web-server/src/utils/formatTaskChanges.ts
This file contains 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,42 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { DatatrakWebTaskChangeRequest, Task } from '@tupaia/types'; | ||
import { stripTimezoneFromDate } from '@tupaia/utils'; | ||
|
||
type Input = Partial<DatatrakWebTaskChangeRequest.ReqBody> & | ||
Partial<Pick<Task, 'entity_id' | 'survey_id' | 'status'>>; | ||
|
||
type Output = Partial<Omit<Task, 'due_date'>> & { | ||
due_date?: string | null; | ||
}; | ||
|
||
export const formatTaskChanges = (task: Input) => { | ||
const { dueDate, repeatSchedule, assigneeId, ...restOfTask } = task; | ||
|
||
const taskDetails: Output & { | ||
due_date?: string | null; | ||
} = { assignee_id: assigneeId, ...restOfTask }; | ||
|
||
if (repeatSchedule) { | ||
// if task is repeating, clear due date | ||
taskDetails.repeat_schedule = JSON.stringify({ | ||
// TODO: format this correctly when recurring tasks are implemented | ||
frequency: repeatSchedule, | ||
}); | ||
taskDetails.due_date = null; | ||
} else if (dueDate) { | ||
// apply status and due date only if not a repeating task | ||
// set due date to end of day | ||
const endOfDay = new Date(new Date(dueDate).setHours(23, 59, 59, 999)); | ||
|
||
// strip timezone from date so that the returned date is always in the user's timezone | ||
const withoutTimezone = stripTimezoneFromDate(endOfDay); | ||
|
||
taskDetails.due_date = withoutTimezone; | ||
} | ||
|
||
return taskDetails; | ||
}; |
45 changes: 45 additions & 0 deletions
45
packages/datatrak-web-server/src/utils/formatTaskResponse.ts
This file contains 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,45 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import { DatatrakWebTaskRequest, Entity, Survey, Task } from '@tupaia/types'; | ||
import camelcaseKeys from 'camelcase-keys'; | ||
|
||
export type TaskT = Omit<Task, 'created_at'> & { | ||
'entity.name': Entity['name']; | ||
'entity.country_code': string; | ||
'survey.code': Survey['code']; | ||
'survey.name': Survey['name']; | ||
task_status: DatatrakWebTaskRequest.ResBody['taskStatus']; | ||
}; | ||
|
||
export const formatTaskResponse = (task: TaskT): DatatrakWebTaskRequest.ResBody => { | ||
const { | ||
entity_id: entityId, | ||
'entity.name': entityName, | ||
'entity.country_code': entityCountryCode, | ||
'survey.code': surveyCode, | ||
survey_id: surveyId, | ||
'survey.name': surveyName, | ||
task_status: taskStatus, | ||
...rest | ||
} = task; | ||
|
||
const formattedTask = { | ||
...rest, | ||
taskStatus, | ||
entity: { | ||
id: entityId, | ||
name: entityName, | ||
countryCode: entityCountryCode, | ||
}, | ||
survey: { | ||
id: surveyId, | ||
name: surveyName, | ||
code: surveyCode, | ||
}, | ||
}; | ||
|
||
return camelcaseKeys(formattedTask) as DatatrakWebTaskRequest.ResBody; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.