Browse Source

Prod fix

merge-requests/372/merge
Oksana Stepanenko 2 years ago committed by Coder
parent
commit
088af584b4
  1. 19
      src/api/tasks/responses.interface.ts
  2. 10
      src/api/tasks/transform.ts
  3. 20
      src/managers/task.manager.ts
  4. 8
      src/modules/tasks/components/tasks-list-with-header.component.tsx
  5. 13
      src/modules/tasks/helpers/index.ts
  6. 8
      src/modules/tasks/hooks/use-tasks-print.hook.ts
  7. 9
      src/modules/tasks/screens/filter-tasks-result.screen.tsx
  8. 5
      src/modules/tasks/screens/group-tasks.screen.tsx
  9. 8
      src/modules/tasks/screens/my-tasks.screen.tsx
  10. 2
      src/modules/tasks/screens/tasks-filter.screen.tsx
  11. 9
      src/modules/tasks/screens/user-tasks.screen.tsx
  12. 2
      src/shared/interfaces/tasks.interfaces.ts

19
src/api/tasks/responses.interface.ts

@ -53,22 +53,23 @@ export interface ITaskWithExecutorPreviewResponse extends ITaskPreviewResponse { @@ -53,22 +53,23 @@ export interface ITaskWithExecutorPreviewResponse extends ITaskPreviewResponse {
}
export interface IFetchMyTasksResponse
extends IPaginationResult<ITaskPreviewResponse> { }
extends IPaginationResult<ITaskPreviewResponse> {}
export interface IFetchUserTasksResponse
extends IPaginationResult<ITaskPreviewResponse> { }
extends IPaginationResult<ITaskPreviewResponse> {}
export interface IFetchGroupTasksResponse
extends IPaginationResult<ITaskWithExecutorPreviewResponse> { }
extends IPaginationResult<ITaskWithExecutorPreviewResponse> {}
export interface IFetchTasksResponse
extends IPaginationResult<ITaskPreviewResponse> { }
extends IPaginationResult<ITaskPreviewResponse> {}
export interface IUserInTask {
userId: number
firstName: string
lastName: string
position?: string
factoryName?: string
}
export interface IExecutorInTask extends IUserInTask {
@ -105,12 +106,13 @@ export interface IFetchTaskDetailsResponse { @@ -105,12 +106,13 @@ export interface IFetchTaskDetailsResponse {
createdAt: string
updatedAt: string
isRead: boolean
factoryName?: string
}
export interface ITaskExecutorResponse extends ITaskExecutor { }
export interface ITaskExecutorResponse extends ITaskExecutor {}
export interface IFetchPotentialTasksExecutorsResponse
extends IPaginationResult<ITaskExecutorResponse> { }
extends IPaginationResult<ITaskExecutorResponse> {}
export interface IUpdateTaskResponse {
id: number
@ -129,10 +131,11 @@ export interface IGetUnreadTasksCountResponse { @@ -129,10 +131,11 @@ export interface IGetUnreadTasksCountResponse {
count: number
}
export interface IGetAllTasksResponseItem extends Omit<ITaskDetails, 'documents'> {
export interface IGetAllTasksResponseItem
extends Omit<ITaskDetails, 'documents'> {
isFavorite: boolean
isRead: boolean
events: Record<string, TaskEvent>[]
comments: IComment[]
documents: ITaskDocument[]
}
}

10
src/api/tasks/transform.ts

@ -10,7 +10,6 @@ import { @@ -10,7 +10,6 @@ import {
ITaskPreviewResponse,
ITaskWithExecutorPreviewResponse,
} from './responses.interface'
import _ from 'lodash'
export const transformExecutorsToShortUsers = (
items: ITaskExecutorResponse[],
@ -59,7 +58,7 @@ export const transformTaskDetails = ( @@ -59,7 +58,7 @@ export const transformTaskDetails = (
task.initiator?.firstName,
task.initiator?.lastName,
),
position: task.author?.position,
position: task.initiator?.position,
},
executor: task.executor && {
id: task.executor?.userId,
@ -67,15 +66,16 @@ export const transformTaskDetails = ( @@ -67,15 +66,16 @@ export const transformTaskDetails = (
task.executor?.firstName,
task.executor?.lastName,
),
position: task.author?.position,
avatarUrl: task.executor?.avatarUrl
position: task.executor?.position,
avatarUrl: task.executor?.avatarUrl,
factoryName: task.executor?.factoryName,
},
group: task.group,
reason: task.reason,
// events: task.events,
createdAt: task.createdAt,
updatedAt: task.updatedAt,
isRead: task.isRead
isRead: task.isRead,
}
return transformedTask

20
src/managers/task.manager.ts

@ -17,7 +17,6 @@ import { @@ -17,7 +17,6 @@ import {
ITaskDocument,
ITaxonomyShortInfo,
PermissionsActions,
TaskEvent,
TaskStatus,
} from '@/shared'
import { PermissionsManager } from './permissions.manager'
@ -660,6 +659,20 @@ export class TaskManager extends Manager { @@ -660,6 +659,20 @@ export class TaskManager extends Manager {
])
}
private transformExecutor(user: DbUserDto): IUserInTask {
if (!user || !user.info) return {} as IUserInTask
return {
..._.pick(user.info, [
'userId',
'firstName',
'lastName',
'avatarUrl',
'position',
]),
factoryName: user.factoryName,
}
}
private transformTaxonomy(taxonomy: DbTaxonomyDto): ITaxonomyShortInfo {
if (!taxonomy) return {} as ITaxonomyShortInfo
return _.pick(taxonomy, ['id', 'name'])
@ -670,7 +683,8 @@ export class TaskManager extends Manager { @@ -670,7 +683,8 @@ export class TaskManager extends Manager {
tasks.map(async it => {
let hasUnreadDocuments = false
it.documents.map(it => {
if (!it.readByUsersId.includes(userId)) hasUnreadDocuments = true
if (!it.readByUsersId.includes(userId))
hasUnreadDocuments = true
})
const hasUnreadComments = _.some(
@ -718,7 +732,7 @@ export class TaskManager extends Manager { @@ -718,7 +732,7 @@ export class TaskManager extends Manager {
...task,
author: this.transformUser(author),
initiator: this.transformUser(initiator),
executor: this.transformUser(executor),
executor: this.transformExecutor(executor),
group: this.transformTaxonomy(group),
reason: this.transformTaxonomy(reason),
}

8
src/modules/tasks/components/tasks-list-with-header.component.tsx

@ -34,6 +34,7 @@ interface IProps { @@ -34,6 +34,7 @@ interface IProps {
payload?: ITaskActionPayload,
) => void
isLoading?: boolean
relativeToDate: string | Date
}
export const TasksListWithHeader: FC<IProps> = ({
@ -46,6 +47,7 @@ export const TasksListWithHeader: FC<IProps> = ({ @@ -46,6 +47,7 @@ export const TasksListWithHeader: FC<IProps> = ({
onSelectTask,
onPressActionBtn,
isLoading,
relativeToDate,
}) => {
const { styles, theme } = useTheme(createStyles)
@ -66,7 +68,11 @@ export const TasksListWithHeader: FC<IProps> = ({ @@ -66,7 +68,11 @@ export const TasksListWithHeader: FC<IProps> = ({
hasUnreadComments={item?.hasUnreadComments}
hasAttachments={item?.hasAttachments}
hasUnreadAttachments={item?.hasUnreadAttachments}
overdue={isOverdueCheck(item.endDate, item.status)}
overdue={isOverdueCheck(
item.endDate,
item.status,
relativeToDate,
)}
imageUrl={hasImageUrl(
item.executor?.avatarUrl,
item.executor?.fullName,

13
src/modules/tasks/helpers/index.ts

@ -33,8 +33,17 @@ export const isUserOwnTask = ( @@ -33,8 +33,17 @@ export const isUserOwnTask = (
userId: number,
) => task?.executor?.id === userId
export const isOverdueCheck = (endDate: string, status: TaskStatus) =>
moment(new Date()).isAfter(endDate) && status === TaskStatus.Active
export const isOverdueCheck = (
endDate: string,
status: TaskStatus,
relativeToDate?: string | Date,
) => {
const targetDate = relativeToDate ? moment(relativeToDate) : moment()
return (
moment(endDate).endOf('day') < targetDate &&
status === TaskStatus.Active
)
}
export const createCardStyles = (items: any[], index: number) => {
let styles: any

8
src/modules/tasks/hooks/use-tasks-print.hook.ts

@ -53,15 +53,17 @@ export const useTasksPrint = () => { @@ -53,15 +53,17 @@ export const useTasksPrint = () => {
<span style="text-decoration: underline">${
task.executor.fullName
}</span></strong>
<span style="font-style:italic">(${task.executor.position})</span>
<span style="font-style:italic">(${task.executor.position}${
task.executor.factoryName ? ', ' : ''
}${task.executor.factoryName ? task.executor.factoryName : ''})</span>
<table >
<tr>
<td style="padding-right: 50px" ><strong>${
task.id
}</strong></td>
<td style="padding-right: 95px"><strong>Початок:</strong> ${moment(
<td style="padding-right: 95px"><strong>Початок:</strong> <span style="font-size: 14">${moment(
new Date(task.startDate),
).format('DD-MM-YYYY')}</td>
).format('DD-MM-YYYY')}</span></td>
<td><strong>Закінчення:</strong>${moment(
new Date(task.endDate),
).format('DD-MM-YYYY')}</td>

9
src/modules/tasks/screens/filter-tasks-result.screen.tsx

@ -10,7 +10,6 @@ import { @@ -10,7 +10,6 @@ import {
} from 'react-native'
import {
$size,
appEvents,
FullTaskActions,
hasImageUrl,
IRouteParams,
@ -23,14 +22,12 @@ import { @@ -23,14 +22,12 @@ import {
} from '@/shared'
import { PartialTheme } from '@/shared/themes/interfaces'
import { useTheme } from '@/shared/hooks/use-theme.hook'
import {
useFetchTasksByFilter,
useTaskActions,
useTaskSelector,
} from '../hooks'
import { SwipableTaskCard, TasksListHeadSmart } from '../smart-components'
import { selectId } from '@/store/account'
import { createCardStyles, isOverdueCheck } from '../helpers'
import { simpleDispatch } from '@/store/store-helpers'
@ -107,7 +104,11 @@ export const FilterTasksResultScreen: FC<IProps> = ({ route, navigation }) => { @@ -107,7 +104,11 @@ export const FilterTasksResultScreen: FC<IProps> = ({ route, navigation }) => {
? true
: false
}
overdue={isOverdueCheck(item.endDate, item.status)}
overdue={isOverdueCheck(
item.endDate,
item.status,
taskFilterProps.taskFilterFields?.date,
)}
hasAttachments={item?.hasAttachments}
hasUnreadAttachments={item?.hasUnreadAttachments}
imageUrl={hasImageUrl(

5
src/modules/tasks/screens/group-tasks.screen.tsx

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
import React, { FC, useState } from 'react'
import {
$size,
appEvents,
hasImageUrl,
IconComponent,
IRouteParams,
@ -11,7 +10,6 @@ import { @@ -11,7 +10,6 @@ import {
} from '@/shared'
import { getTitleByCount } from '@/shared/helpers'
import { useTheme } from '@/shared/hooks/use-theme.hook'
import { PartialTheme } from '@/shared/themes/interfaces'
import { simpleDispatch } from '@/store/store-helpers'
import { UnselectAllUsers, UnselectExecutor } from '@/store/users'
import _ from 'lodash'
@ -117,12 +115,13 @@ export const GroupTasksScreen: FC<IProps> = ({ route, navigation }) => { @@ -117,12 +115,13 @@ export const GroupTasksScreen: FC<IProps> = ({ route, navigation }) => {
onSelectTask={task => handleSelectTask(task as any)}
onPressActionBtn={handlePressOneTaskAction}
isLoading={isLoadingNext}
relativeToDate={taskFilterProps.taskFilterFields?.date}
/>
</ScreenLayout>
)
}
const createStyles = (theme: PartialTheme) =>
const createStyles = () =>
StyleSheet.create({
header: {
paddingTop: $size(10, 10),

8
src/modules/tasks/screens/my-tasks.screen.tsx

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
import React, { FC, useEffect, useState } from 'react'
import React, { FC, useState } from 'react'
import { StyleSheet } from 'react-native'
import { useSelector } from 'react-redux'
import {
@ -11,7 +11,6 @@ import { @@ -11,7 +11,6 @@ import {
ScreenLayout,
} from '@/shared'
import { useTheme } from '@/shared/hooks/use-theme.hook'
import { PartialTheme } from '@/shared/themes/interfaces'
import { selectAccount } from '@/store/account'
import _ from 'lodash'
import { TasksListWithHeader } from '../components'
@ -24,7 +23,7 @@ import { TasksListHeadSmart } from '../smart-components' @@ -24,7 +23,7 @@ import { TasksListHeadSmart } from '../smart-components'
interface IProps extends IRouteParams {}
export const MyTasksScreen: FC<IProps> = ({ navigation, route }) => {
export const MyTasksScreen: FC<IProps> = ({ navigation }) => {
const { styles } = useTheme(createStyles)
const { info } = useSelector(selectAccount)
@ -90,12 +89,13 @@ export const MyTasksScreen: FC<IProps> = ({ navigation, route }) => { @@ -90,12 +89,13 @@ export const MyTasksScreen: FC<IProps> = ({ navigation, route }) => {
onSelectTask={task => handleSelectTask(task)}
onPressActionBtn={handlePressOneTaskAction}
isLoading={isLoadingNext}
relativeToDate={taskFilterProps.taskFilterFields?.date}
/>
</ScreenLayout>
)
}
const createStyles = (theme: PartialTheme) =>
const createStyles = () =>
StyleSheet.create({
header: {
paddingTop: $size(10, 10),

2
src/modules/tasks/screens/tasks-filter.screen.tsx

@ -85,7 +85,7 @@ export const TasksFilterScreen: FC<ITaskFilterProps> = ({ @@ -85,7 +85,7 @@ export const TasksFilterScreen: FC<ITaskFilterProps> = ({
}
const maxDates = {
[DateKeysEnum.DATE]: new Date(),
[DateKeysEnum.DATE]: null,
[DateKeysEnum.END_DATE]: null,
[DateKeysEnum.START_DATE]: taskFilterFields.endDate,
}

9
src/modules/tasks/screens/user-tasks.screen.tsx

@ -1,9 +1,6 @@ @@ -1,9 +1,6 @@
import React, { FC, useState } from 'react'
import { StyleSheet } from 'react-native'
import _ from 'lodash'
import { PartialTheme } from '@/shared/themes/interfaces'
import {
$size,
hasImageUrl,
@ -14,7 +11,6 @@ import { @@ -14,7 +11,6 @@ import {
useSelectExecutor,
} from '@/shared'
import { useTheme } from '@/shared/hooks/use-theme.hook'
import { TasksListWithHeader } from '../components'
import {
useFetchTasksByFilter,
@ -33,7 +29,7 @@ interface IProps extends IRouteParams { @@ -33,7 +29,7 @@ interface IProps extends IRouteParams {
}
export const UserTasksScreen: FC<IProps> = ({ route, navigation }) => {
const { styles, theme } = useTheme(createStyles)
const { styles } = useTheme(createStyles)
const { id, fullName, avatarUrl, position } = route.params.userData
const [isOpenDrawer, setDrawer] = useState<boolean>(false)
@ -108,12 +104,13 @@ export const UserTasksScreen: FC<IProps> = ({ route, navigation }) => { @@ -108,12 +104,13 @@ export const UserTasksScreen: FC<IProps> = ({ route, navigation }) => {
onSelectTask={task => handleSelectTask(task)}
onPressActionBtn={handlePressOneTaskAction}
isLoading={isLoadingNext}
relativeToDate={taskFilterProps.taskFilterFields?.date}
/>
</ScreenLayout>
)
}
const createStyles = (theme: PartialTheme) =>
const createStyles = () =>
StyleSheet.create({
header: {
paddingTop: $size(10, 10),

2
src/shared/interfaces/tasks.interfaces.ts

@ -46,7 +46,7 @@ export interface IFullTaskInfo extends ITaskDetails { @@ -46,7 +46,7 @@ export interface IFullTaskInfo extends ITaskDetails {
isRead?: boolean
author?: IShortUser
initiator?: IShortUser
executor?: IShortUser
executor?: IShortUser & { factoryName?: string }
group?: ITaxonomyShortInfo
reason?: ITaxonomyShortInfo
// events?: Record<string, TaskEvent>[]

Loading…
Cancel
Save