From e550f89393a97089426d80c24f8e47abccdca959 Mon Sep 17 00:00:00 2001 From: troff8 Date: Tue, 20 Jun 2023 11:43:47 +0400 Subject: [PATCH] feat(GoalCreateForm): goal button improvements --- .../GoalCreateForm/GoalCreateForm.i18n/en.json | 2 +- .../GoalCreateForm/GoalCreateForm.i18n/ru.json | 2 +- src/components/GoalCreateForm/GoalCreateForm.tsx | 10 +++++----- src/hooks/useLocalStorage.ts | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/GoalCreateForm/GoalCreateForm.i18n/en.json b/src/components/GoalCreateForm/GoalCreateForm.i18n/en.json index 3b247c57c..484263844 100644 --- a/src/components/GoalCreateForm/GoalCreateForm.i18n/en.json +++ b/src/components/GoalCreateForm/GoalCreateForm.i18n/en.json @@ -3,7 +3,7 @@ "Press key to create the goal": "Press {key} to create the goal.", "Create & Go": "Create & Go", "Create one more": "Create one more", - "Create": "Create", + "Create only": "Create only", "Create and go to the goal page": "Create and go to the goal page", "Create and open new form for the next goal": "Create and open new form for the next goal", "Create goal and close form": "Create goal and close form", diff --git a/src/components/GoalCreateForm/GoalCreateForm.i18n/ru.json b/src/components/GoalCreateForm/GoalCreateForm.i18n/ru.json index edd7af366..efe99915a 100644 --- a/src/components/GoalCreateForm/GoalCreateForm.i18n/ru.json +++ b/src/components/GoalCreateForm/GoalCreateForm.i18n/ru.json @@ -3,7 +3,7 @@ "Press key to create the goal": "Нажми {key}, чтобы создать цель.", "Create & Go": "Создать и перейти", "Create one more": "Создать еще", - "Create": "Создать", + "Create only": "Создать", "Create and go to the goal page": "Создать и перейти на страницу цели", "Create and open new form for the next goal": "Создать и открыть новую форму для следующей цели", "Create goal and close form": "Создать цель и закрыть форму", diff --git a/src/components/GoalCreateForm/GoalCreateForm.tsx b/src/components/GoalCreateForm/GoalCreateForm.tsx index fe3035328..8831d9490 100644 --- a/src/components/GoalCreateForm/GoalCreateForm.tsx +++ b/src/components/GoalCreateForm/GoalCreateForm.tsx @@ -38,9 +38,9 @@ const GoalCreateForm: React.FC = () => { const [lastProjectCache, setLastProjectCache] = useLocalStorage('lastProjectCache'); const [currentProjectCache] = useLocalStorage('currentProjectCache'); const [recentProjectsCache, setRecentProjectsCache] = useLocalStorage('recentProjectsCache', {}); + const [goalCreateFormActionCache, setGoalCreateFormActionCache] = useLocalStorage('goalCreateFormAction'); const [busy, setBusy] = useState(false); - const [actionBtnText, setActionBtnText] = useState(tr('Create & Go')); - const [createGoalType, setСreateGoalType] = useState(1); + const [createGoalType, setСreateGoalType] = useState(goalCreateFormActionCache || 3); const createOptions = [ { @@ -54,7 +54,7 @@ const GoalCreateForm: React.FC = () => { value: 2, }, { - title: tr('Create'), + title: tr('Create only'), clue: tr('Create goal and close form'), value: 3, }, @@ -63,7 +63,6 @@ const GoalCreateForm: React.FC = () => { type CreateOptions = typeof createOptions; const onCreateTypeChange = useCallback((item: CreateOptions[number]) => { setСreateGoalType(item.value); - setActionBtnText(item.title); }, []); const createMutation = trpc.goal.create.useMutation(); const createGoal = async (form: GoalCommon) => { @@ -83,6 +82,7 @@ const GoalCreateForm: React.FC = () => { } setRecentProjectsCache(newRecentProjectsCache); setLastProjectCache(form.parent); + setGoalCreateFormActionCache(createGoalType); if (createGoalType === 1) { router.goal(res._shortId); @@ -121,7 +121,7 @@ const GoalCreateForm: React.FC = () => { outline type="submit" brick="right" - text={actionBtnText} + text={createOptions[createGoalType - 1].title} /> ; +export type GoalCreateFormAction = number | null; type SetValue = (value: TValue | ((previousValue: TValue) => TValue)) => void; interface StorageKey { lastProjectCache: LastOrCurrentProject; currentProjectCache: LastOrCurrentProject; recentProjectsCache: RecentProjectsCache; + goalCreateFormAction: GoalCreateFormAction; } export function useLocalStorage(