Skip to content

Commit

Permalink
feat(GoalHistory): recordings changes
Browse files Browse the repository at this point in the history
feat(GoalHistory): for tags, title, desc, project, owner, priority
  • Loading branch information
LamaEats committed May 29, 2023
1 parent dac32ee commit d81dc71
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 98 deletions.
3 changes: 2 additions & 1 deletion src/components/GoalCreateForm/GoalCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Tip } from '../Tip';
import { Keyboard } from '../Keyboard';
import { GoalForm } from '../GoalForm/GoalForm';
import { trpc } from '../../utils/trpcClient';
import { GoalCommon } from '../../schema/goal';
import { GoalCommon, goalCommonSchema } from '../../schema/goal';
import { ActivityByIdReturnType } from '../../../trpc/inferredTypes';
import { notifyPromise } from '../../utils/notifyPromise';

Expand Down Expand Up @@ -61,6 +61,7 @@ const GoalCreateForm: React.FC = () => {
return (
<GoalForm
busy={busy}
validityScheme={goalCommonSchema}
formTitle={tr('New goal')}
owner={{ id: user?.activityId, user } as ActivityByIdReturnType}
parent={currentProjectCache || lastProjectCache || undefined}
Expand Down
6 changes: 4 additions & 2 deletions src/components/GoalEditForm/GoalEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useState } from 'react';
import { GoalForm } from '../GoalForm/GoalForm';
import { GoalByIdReturnType } from '../../../trpc/inferredTypes';
import { useGoalUpdate } from '../../hooks/useGoalUpdate';
import { GoalCommon } from '../../schema/goal';
import { GoalUpdate, goalUpdateSchema } from '../../schema/goal';

import { tr } from './GoalEditForm.i18n';

Expand All @@ -17,7 +17,7 @@ const GoalEditForm: React.FC<GoalEditFormProps> = ({ goal, onSubmit }) => {
const [busy, setBusy] = useState(false);
const update = useGoalUpdate(goal.id);

const updateGoal = async (form: GoalCommon) => {
const updateGoal = async (form: GoalUpdate) => {
setBusy(true);

await update(form);
Expand All @@ -28,6 +28,8 @@ const GoalEditForm: React.FC<GoalEditFormProps> = ({ goal, onSubmit }) => {
// FIXME: nullable values are conflicting with undefined
return (
<GoalForm
validityScheme={goalUpdateSchema}
id={goal.id}
busy={busy}
formTitle={tr('Edit the goal')}
title={goal.title}
Expand Down
15 changes: 10 additions & 5 deletions src/components/GoalForm/GoalForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useState } from 'react';
import { useForm, Controller } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { Schema, z } from 'zod';
import styled from 'styled-components';
import { gapS, gray2 } from '@taskany/colors';
import {
Expand All @@ -27,7 +28,6 @@ import { EstimateComboBox } from '../EstimateComboBox';
import { TagComboBox } from '../TagComboBox';
import { StateDropdown } from '../StateDropdown';
import { PriorityDropdown } from '../PriorityDropdown';
import { GoalCommon, goalCommonSchema } from '../../schema/goal';
import { ActivityByIdReturnType } from '../../../trpc/inferredTypes';

import { tr } from './GoalForm.i18n';
Expand All @@ -47,8 +47,10 @@ interface GoalFormProps {
estimate?: Estimate;
busy?: boolean;
children?: React.ReactNode;
validityScheme: Schema;
id?: string;

onSumbit: (fields: GoalCommon) => void;
onSumbit: (fields: z.infer<GoalFormProps['validityScheme']>) => void;
}

const StyledTagsContainer = styled.div<{ focused?: boolean }>`
Expand All @@ -65,6 +67,7 @@ const StyledTagsContainer = styled.div<{ focused?: boolean }>`
export const GoalForm: React.FC<GoalFormProps> = ({
formTitle,
actionBtnText,
id,
title,
description,
owner,
Expand All @@ -74,6 +77,7 @@ export const GoalForm: React.FC<GoalFormProps> = ({
priority,
estimate,
busy,
validityScheme,
children,
onSumbit,
}) => {
Expand All @@ -96,8 +100,8 @@ export const GoalForm: React.FC<GoalFormProps> = ({
setFocus,
setValue,
formState: { errors, isValid, isSubmitted },
} = useForm<GoalCommon>({
resolver: zodResolver(goalCommonSchema),
} = useForm<z.infer<typeof validityScheme>>({
resolver: zodResolver(validityScheme),
mode: 'onChange',
reValidateMode: 'onChange',
shouldFocusError: false,
Expand All @@ -110,11 +114,12 @@ export const GoalForm: React.FC<GoalFormProps> = ({
priority,
estimate,
tags,
id,
},
});

const parentWatcher = watch('parent');
const tagsWatcher = watch('tags');
const tagsWatcher: TagModel[] = watch('tags');
const errorsResolver = errorsProvider(errors, isSubmitted);

useEffect(() => {
Expand Down
1 change: 0 additions & 1 deletion src/components/GoalPage/GoalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { IssueParent } from '../IssueParent';
import { IssueTags } from '../IssueTags';
import { getPriorityText } from '../PriorityText/PriorityText';
import { useHighlightedComment } from '../../hooks/useHighlightedComment';
import { useGoalUpdate } from '../../hooks/useGoalUpdate';
import { useLocalStorage } from '../../hooks/useLocalStorage';
import { useWillUnmount } from '../../hooks/useWillUnmount';
import { ActivityFeed } from '../ActivityFeed';
Expand Down
1 change: 0 additions & 1 deletion src/components/GoalPreview/GoalPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
import { refreshInterval } from '../../utils/config';
import { formatEstimate } from '../../utils/dateTime';
import { useHighlightedComment } from '../../hooks/useHighlightedComment';
import { useGoalUpdate } from '../../hooks/useGoalUpdate';
import { routes } from '../../hooks/router';
import { usePageContext } from '../../hooks/usePageContext';
import { useReactionsResource } from '../../hooks/useReactionsResource';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const IssueParticipantsForm: React.FC<IssueParticipantsFormProps> = ({ pa
(id: string) => {
activities.delete(id);

onChange?.(Array.from(activities).map(([_, p]) => p));
onChange?.(Array.from(activities.values()));
},
[activities, onChange],
);
Expand All @@ -58,7 +58,7 @@ export const IssueParticipantsForm: React.FC<IssueParticipantsFormProps> = ({ pa

setQuery('');

onChange?.(Array.from(activities).map(([_, p]) => p));
onChange?.(Array.from(activities.values()));
},
[activities, onChange],
);
Expand Down
93 changes: 39 additions & 54 deletions src/schema/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,62 +99,47 @@ export const goalUpdateSchema = z.object({
})
.min(10, {
message: tr("Goal's description must be longer than 10 symbols"),
})
.optional(),
description: z
.string({
required_error: tr("Goal's description is required"),
invalid_type_error: tr("Goal's description must be a string"),
})
.optional(),
owner: z
.object({
}),
description: z.string({
required_error: tr("Goal's description is required"),
invalid_type_error: tr("Goal's description must be a string"),
}),
owner: z.object({
id: z.string(),
user: z.object({
nickname: z.string().nullable(),
name: z.string().nullable(),
email: z.string(),
}),
}),
parent: z.object(
{
id: z.string(),
})
.optional(),
parent: z
.object(
{
id: z.string(),
title: z.string(),
flowId: z.string(),
},
{
invalid_type_error: tr("Goal's project or team are required"),
required_error: tr("Goal's project or team are required"),
},
)
.optional(),
state: z
.object({
title: z.string(),
flowId: z.string(),
},
{
invalid_type_error: tr("Goal's project or team are required"),
required_error: tr("Goal's project or team are required"),
},
),
state: z.object({
id: z.string(),
hue: z.number().optional(),
title: z.string().optional(),
}),
priority: z.string().nullable(),
estimate: z.object({
date: z.string(),
q: z.string(),
y: z.string(),
}),
tags: z.array(
z.object({
id: z.string(),
hue: z.number().optional(),
title: z.string().optional(),
})
.optional(),
priority: z.string().nullable().optional(),
estimate: z
.object({
date: z.string(),
q: z.string(),
y: z.string(),
})
.optional(),
tags: z
.array(
z.object({
id: z.string(),
title: z.string(),
}),
)
.optional(),
participants: z
.array(
z.object({
id: z.string(),
}),
)
.optional(),
title: z.string(),
}),
),
});

export type GoalUpdate = z.infer<typeof goalUpdateSchema>;
Expand Down
11 changes: 0 additions & 11 deletions src/schema/goalHistory.ts

This file was deleted.

Loading

0 comments on commit d81dc71

Please sign in to comment.