Skip to content

Commit

Permalink
feat(GoalSidebar): clone goal
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats committed Aug 1, 2024
1 parent 2fe1968 commit 2fde536
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
32 changes: 23 additions & 9 deletions src/components/GoalCreateForm/GoalCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { dispatchModalEvent, ModalEvent } from '../../utils/dispatchModal';
import { GoalForm } from '../GoalForm/GoalForm';
import { trpc } from '../../utils/trpcClient';
import { GoalCommon, goalCommonSchema } from '../../schema/goal';
import { ActivityByIdReturnType, GoalCreateReturnType } from '../../../trpc/inferredTypes';
import { ActivityByIdReturnType, GoalByIdReturnType, GoalCreateReturnType } from '../../../trpc/inferredTypes';
import { useGoalResource } from '../../hooks/useGoalResource';
import {
combobox,
Expand All @@ -28,13 +28,25 @@ import { Dropdown, DropdownPanel, DropdownTrigger } from '../Dropdown/Dropdown';
import { tr } from './GoalCreateForm.i18n';
import s from './GoalCreateForm.module.css';

interface GoalCreateFormProps {
title?: string;
interface GoalCreateFormProps
extends Partial<Pick<NonNullable<GoalByIdReturnType>, 'priority' | 'description' | 'title' | 'personal' | 'tags'>> {
onGoalCreate?: (val: GoalCreateReturnType) => void;
personal?: boolean;
project?: {
id: string;
title: string;
flowId: string;
} | null;
}

const GoalCreateForm: React.FC<GoalCreateFormProps> = ({ title, onGoalCreate, personal }) => {
const GoalCreateForm: React.FC<GoalCreateFormProps> = ({
title,
onGoalCreate,
personal,
project,
description,
priority,
tags,
}) => {
const router = useRouter();
const { user } = usePageContext();
const [goalCreateFormActionCache, setGoalCreateFormActionCache] = useLocalStorage('goalCreateFormAction');
Expand Down Expand Up @@ -139,12 +151,14 @@ const GoalCreateForm: React.FC<GoalCreateFormProps> = ({ title, onGoalCreate, pe
<GoalForm
busy={busy}
validitySchema={goalCommonSchema}
owner={{ id: user?.activityId, user } as ActivityByIdReturnType}
parent={parent ?? undefined}
personal={personal}
priority={defaultPriority ?? undefined}
personal={!!personal}
onSubmit={createGoal}
title={title}
description={description}
owner={{ id: user?.activityId, user } as ActivityByIdReturnType}
parent={project ?? parent ?? undefined}
priority={priority ?? defaultPriority ?? undefined}
tags={tags}
actionButton={
<FormAction className={s.FormActions}>
<Button
Expand Down
3 changes: 2 additions & 1 deletion src/components/GoalSidebar/GoalSidebar.i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"relatedTo": "Relates to",
"Delete": "",
"Connect to goal": "",
"Is the criteria for": ""
"Is the criteria for": "",
"Clone goal": ""
}
3 changes: 2 additions & 1 deletion src/components/GoalSidebar/GoalSidebar.i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"relatedTo": "Связана с",
"Delete": "Удалить",
"Connect to goal": "Привязать к цели",
"Is the criteria for": "Является критерием для"
"Is the criteria for": "Является критерием для",
"Clone goal": "Клонировать цель"
}
8 changes: 7 additions & 1 deletion src/components/GoalSidebar/GoalSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentProps, FC, useCallback, useMemo } from 'react';
import { nullable } from '@taskany/bricks';
import { Tag, TagCleanButton } from '@taskany/bricks/harmony';
import { IconArrowRightOutline, IconBinOutline, IconXCircleSolid } from '@taskany/icons';
import { IconArrowRightOutline, IconBinOutline, IconLayersSubtractOutline, IconXCircleSolid } from '@taskany/icons';

import { IssueMeta } from '../IssueMeta/IssueMeta';
import { UserBadge } from '../UserBadge/UserBadge';
Expand Down Expand Up @@ -336,6 +336,12 @@ export const GoalSidebar: FC<GoalSidebarProps> = ({ goal, onGoalTransfer, onGoal
)}
/>
<br />
<AddInlineTrigger
icon={<IconLayersSubtractOutline size="xs" />}
text={tr('Clone goal')}
onClick={dispatchModalEvent(ModalEvent.GoalCreateModal, goal)}
/>
<br />
<AddInlineTrigger
icon={<IconBinOutline size="xs" {...goalPageDeleteButton.attr} />}
text={tr('Archive goal')}
Expand Down
7 changes: 3 additions & 4 deletions src/utils/dispatchModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ export enum ModalEvent {

export interface MapModalToComponentProps {
[ModalEvent.GoalCreateModal]: {
onGoalCreate?: (goal: GoalCreateReturnType) => void;
project?: {
id: string;
title: string;
flowId: string;
};
title?: string;
onGoalCreate?: (goal: GoalCreateReturnType) => void;
};
} | null;
} & Partial<Pick<NonNullable<GoalByIdReturnType>, 'priority' | 'description' | 'title' | 'personal' | 'tags'>>;
[ModalEvent.ProjectSwitchPublicConfirmModal]: {
onConfirm?: () => void;
};
Expand Down

0 comments on commit 2fde536

Please sign in to comment.