Skip to content

Commit

Permalink
fix: gets the selected project role info in order to show duration ti…
Browse files Browse the repository at this point in the history
…me info
  • Loading branch information
ssubijana committed Oct 3, 2023
1 parent f95b06e commit b7683cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export const ActivityForm: FC<ActivityFormProps> = (props) => {
}
}

const role = useMemo(() => {
const role: ProjectRole | NonHydratedProjectRole | undefined = useMemo(() => {
return showRecentRole ? recentProjectRole : projectRole
}, [projectRole, showRecentRole, recentProjectRole])

Expand Down Expand Up @@ -248,10 +248,6 @@ export const ActivityForm: FC<ActivityFormProps> = (props) => {
setValue('file', files[0])
}

const activeRole: ProjectRole | NonHydratedProjectRole | undefined = showRecentRole
? recentProjectRole
: projectRole

return (
<Grid
templateColumns="repeat(6, [col] 1fr)"
Expand Down Expand Up @@ -341,14 +337,13 @@ export const ActivityForm: FC<ActivityFormProps> = (props) => {
wrap="wrap"
position="relative"
>
{activeRole !== undefined && (
{role !== undefined && (
<DurationText
// TODO: Remove once there is a dedicated TimeInfo API
isRecentRole={showRecentRole}
timeInfo={activeRole.timeInfo}
timeInfo={role.timeInfo}
projectId={project?.id}
roleId={activeRole.id}
selectedRoleId={projectRole?.id}
roleId={role.id}
userId={activity?.userId}
useDecimalTimeFormat={settings?.useDecimalTimeFormat}
start={interval.start}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface Props {
isRecentRole: boolean
projectId?: Id
userId?: Id
selectedRoleId?: Id
// TODO: Until here
roleId?: Id
start: Date
Expand Down Expand Up @@ -50,20 +49,19 @@ export const DurationText: FC<Props> = (props) => {

// TODO: Remove once there is a dedicated TimeInfo API
useEffect(() => {
if (props.projectId !== undefined && props.selectedRoleId !== undefined) {
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.selectedRoleId)

const find = x.find((role) => role.id === props.roleId)
if (find !== undefined) {
setTimeInfo(find.timeInfo)
}
})
}
}, [executeUseCase, props.projectId, props.roleId, props.selectedRoleId, props.userId, start])
}, [executeUseCase, props.projectId, props.roleId, props.userId, start])

const { isLoading: daysLoading, executeUseCase: getDaysForActivityDaysPeriodQry } = useGetUseCase(
GetDaysForActivityDaysPeriodQry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const SelectRoleSection: FC<Props> = (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<HTMLInputElement>(null)

Expand Down Expand Up @@ -64,6 +65,7 @@ export const SelectRoleSection: FC<Props> = (props: Props) => {
showRecentRoleField.onChange(false)
}}
onChange={(value) => {
projectField.onChange(value.project)
recentProjectRoleField.onChange(value)
}}
projectRole={recentProjectRoleField.value}
Expand Down

0 comments on commit b7683cf

Please sign in to comment.