diff --git a/src/features/binnacle/features/activity/ui/components/activity-form/activity-form.tsx b/src/features/binnacle/features/activity/ui/components/activity-form/activity-form.tsx index bbc082c8..da33b261 100644 --- a/src/features/binnacle/features/activity/ui/components/activity-form/activity-form.tsx +++ b/src/features/binnacle/features/activity/ui/components/activity-form/activity-form.tsx @@ -342,7 +342,6 @@ export const ActivityForm: FC = (props) => { // TODO: Remove once there is a dedicated TimeInfo API isRecentRole={showRecentRole} timeInfo={role.timeInfo} - projectId={project?.id} roleId={role.id} userId={activity?.userId} useDecimalTimeFormat={settings?.useDecimalTimeFormat} diff --git a/src/features/binnacle/features/activity/ui/components/activity-form/components/duration-text.tsx b/src/features/binnacle/features/activity/ui/components/activity-form/components/duration-text.tsx index 7cc2831b..41f77726 100644 --- a/src/features/binnacle/features/activity/ui/components/activity-form/components/duration-text.tsx +++ b/src/features/binnacle/features/activity/ui/components/activity-form/components/duration-text.tsx @@ -9,14 +9,12 @@ import { DateInterval } from '../../../../../../../../shared/types/date-interval import { GetDaysForActivityDaysPeriodQry } from '../../../../application/get-days-for-activity-days-period-qry' import { GetDaysForActivityNaturalDaysPeriodQry } from '../../../../application/get-days-for-activity-natural-days-period-qry' import { Id } from '../../../../../../../../shared/types/id' -import { GetProjectRolesQry } from '../../../../../project-role/application/get-project-roles-qry' import { TimeInfo } from '../../../../../project-role/domain/project-role-time-info' interface Props { // TODO: Remove once there is a dedicated TimeInfo API timeInfo: TimeInfo isRecentRole: boolean - projectId?: Id userId?: Id // TODO: Until here roleId?: Id @@ -29,39 +27,6 @@ export const DurationText: FC = (props) => { const { start, end, useDecimalTimeFormat } = props const { t } = useTranslation() const [numberOfDays, setNumberOfDays] = useState(null) - const [timeInfo, setTimeInfo] = useState({ - timeUnit: TimeUnits.MINUTES, - maxTimeAllowed: { - byActivity: 0, - byYear: 0 - }, - userRemainingTime: 0 - }) - - // TODO: Remove once there is a dedicated TimeInfo API - useEffect(() => { - if (props.isRecentRole) { - setTimeInfo(props.timeInfo) - } - }, [props.isRecentRole, props.timeInfo]) - - const { executeUseCase, isLoading } = useGetUseCase(GetProjectRolesQry) - - // TODO: Remove once there is a dedicated TimeInfo API - useEffect(() => { - if (props.projectId !== undefined && props.roleId !== undefined) { - executeUseCase({ - projectId: props.projectId, - userId: props.userId, - year: start.getFullYear() - }).then((x) => { - const find = x.find((role) => role.id === props.roleId) - if (find !== undefined) { - setTimeInfo(find.timeInfo) - } - }) - } - }, [executeUseCase, props.projectId, props.roleId, props.userId, start]) const { isLoading: daysLoading, executeUseCase: getDaysForActivityDaysPeriodQry } = useGetUseCase( GetDaysForActivityDaysPeriodQry @@ -72,38 +37,38 @@ export const DurationText: FC = (props) => { const formatTimePerTimeUnit = useCallback( (timeToFormat: number) => { - return timeInfo.timeUnit === TimeUnits.MINUTES + return props.timeInfo.timeUnit === TimeUnits.MINUTES ? getDurationByMinutes(timeToFormat) : getHumanizedDuration({ duration: timeToFormat, abbreviation: true, - timeUnit: timeInfo.timeUnit + timeUnit: props.timeInfo.timeUnit }) }, - [timeInfo.timeUnit] + [props.timeInfo.timeUnit] ) const duration = useMemo(() => { - const diffUnit = timeInfo.timeUnit === TimeUnits.MINUTES ? 'minute' : 'businessDay' + const diffUnit = props.timeInfo.timeUnit === TimeUnits.MINUTES ? 'minute' : 'businessDay' const difference = chrono(start).diff(end, diffUnit) - return timeInfo.timeUnit === TimeUnits.MINUTES + return props.timeInfo.timeUnit === TimeUnits.MINUTES ? getDurationByMinutes(difference, useDecimalTimeFormat) : getHumanizedDuration({ duration: numberOfDays || 0, abbreviation: true, - timeUnit: timeInfo.timeUnit + timeUnit: props.timeInfo.timeUnit }) - }, [timeInfo.timeUnit, end, start, useDecimalTimeFormat, numberOfDays]) + }, [props.timeInfo.timeUnit, end, start, useDecimalTimeFormat, numberOfDays]) useEffect(() => { - if (timeInfo.timeUnit === TimeUnits.MINUTES) { + if (props.timeInfo.timeUnit === TimeUnits.MINUTES) { return } const dateInterval: DateInterval = { start, end } - if (timeInfo.timeUnit === TimeUnits.DAYS) { + if (props.timeInfo.timeUnit === TimeUnits.DAYS) { getDaysForActivityDaysPeriodQry(dateInterval).then(setNumberOfDays) - } else if (timeInfo.timeUnit === TimeUnits.NATURAL_DAYS && props.roleId !== undefined) { + } else if (props.timeInfo.timeUnit === TimeUnits.NATURAL_DAYS && props.roleId !== undefined) { getDaysForActivityNaturalDaysPeriodQry({ roleId: props.roleId, interval: dateInterval }).then( setNumberOfDays ) @@ -112,51 +77,47 @@ export const DurationText: FC = (props) => { start, end, getDaysForActivityDaysPeriodQry, - timeInfo.timeUnit, + props.timeInfo.timeUnit, props.roleId, getDaysForActivityNaturalDaysPeriodQry ]) return ( <> - {!isLoading && ( - <> - - {t('activity_form.duration')} - {daysLoading || naturalDaysLoading ? ( - {t('accessibility.loading')} - ) : ( - {duration} - )} - + + {t('activity_form.duration')} + {daysLoading || naturalDaysLoading ? ( + {t('accessibility.loading')} + ) : ( + {duration} + )} + - - {timeInfo.maxTimeAllowed.byYear > 0 && ( - - {t('activity_form.remainingByYear', { - remaining: formatTimePerTimeUnit(timeInfo.userRemainingTime), - maxAllowed: formatTimePerTimeUnit(timeInfo.maxTimeAllowed.byYear) - })} - - )} + + {props.timeInfo.maxTimeAllowed.byYear > 0 && ( + + {t('activity_form.remainingByYear', { + remaining: formatTimePerTimeUnit(props.timeInfo.userRemainingTime), + maxAllowed: formatTimePerTimeUnit(props.timeInfo.maxTimeAllowed.byYear) + })} + + )} - {timeInfo.maxTimeAllowed.byActivity > 0 && ( - - {t('activity_form.remainingByActivity', { - maxAllowed: formatTimePerTimeUnit(timeInfo.maxTimeAllowed.byActivity) - })} - - )} - - - )} + {props.timeInfo.maxTimeAllowed.byActivity > 0 && ( + + {t('activity_form.remainingByActivity', { + maxAllowed: formatTimePerTimeUnit(props.timeInfo.maxTimeAllowed.byActivity) + })} + + )} + ) } diff --git a/src/features/binnacle/features/activity/ui/components/activity-form/components/select-role-section.tsx b/src/features/binnacle/features/activity/ui/components/activity-form/components/select-role-section.tsx index e004c8c5..ed46956f 100644 --- a/src/features/binnacle/features/activity/ui/components/activity-form/components/select-role-section.tsx +++ b/src/features/binnacle/features/activity/ui/components/activity-form/components/select-role-section.tsx @@ -20,7 +20,6 @@ export const SelectRoleSection: FC = (props: Props) => { const { t } = useTranslation() const { field: showRecentRoleField } = useController({ control, name: 'showRecentRole' }) const { field: recentProjectRoleField } = useController({ control, name: 'recentProjectRole' }) - const { field: projectField } = useController({ control, name: 'project' }) const [recentRoleListIsEmpty, setRecentRoleListIsEmpty] = useState(false) const organizationRef = useRef(null) @@ -65,7 +64,6 @@ export const SelectRoleSection: FC = (props: Props) => { showRecentRoleField.onChange(false) }} onChange={(value) => { - projectField.onChange(value.project) recentProjectRoleField.onChange(value) }} projectRole={recentProjectRoleField.value}