Skip to content

Commit

Permalink
feat(GoalCreateForm): goal button improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Troff8 committed Jun 20, 2023
1 parent c73e738 commit e550f89
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/GoalCreateForm/GoalCreateForm.i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/GoalCreateForm/GoalCreateForm.i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Создать цель и закрыть форму",
Expand Down
10 changes: 5 additions & 5 deletions src/components/GoalCreateForm/GoalCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(tr('Create & Go'));
const [createGoalType, setСreateGoalType] = useState<number>(1);
const [createGoalType, setСreateGoalType] = useState<number>(goalCreateFormActionCache || 3);

const createOptions = [
{
Expand All @@ -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,
},
Expand All @@ -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) => {
Expand All @@ -83,6 +82,7 @@ const GoalCreateForm: React.FC = () => {
}
setRecentProjectsCache(newRecentProjectsCache);
setLastProjectCache(form.parent);
setGoalCreateFormActionCache(createGoalType);

if (createGoalType === 1) {
router.goal(res._shortId);
Expand Down Expand Up @@ -121,7 +121,7 @@ const GoalCreateForm: React.FC = () => {
outline
type="submit"
brick="right"
text={actionBtnText}
text={createOptions[createGoalType - 1].title}
/>
<Dropdown
placement="top-end"
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useLocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export type RecentProjectsCache = Record<
string,
{ rate: number; cache: { id: string; title: string; flowId: string; description?: string | null } }
>;
export type GoalCreateFormAction = number | null;
type SetValue<TValue> = (value: TValue | ((previousValue: TValue) => TValue)) => void;
interface StorageKey {
lastProjectCache: LastOrCurrentProject;
currentProjectCache: LastOrCurrentProject;
recentProjectsCache: RecentProjectsCache;
goalCreateFormAction: GoalCreateFormAction;
}

export function useLocalStorage<T extends keyof StorageKey>(
Expand Down

0 comments on commit e550f89

Please sign in to comment.