Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Board Settings Info cancel button to reset info #490

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions frontend/src/components/Board/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, SetStateAction, useEffect, useMemo, useRef, useState } from 'react';
import { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { useRecoilValue } from 'recoil';
import { joiResolver } from '@hookform/resolvers/joi';
Expand Down Expand Up @@ -61,14 +61,15 @@ const BoardSettings = ({
const { board } = useRecoilValue(boardInfoState);

// State used to change values
const [data, setData] = useState<UpdateBoardType>({
const initialData: UpdateBoardType = {
_id: board?._id,
hideCards: board?.hideCards,
hideVotes: board?.hideVotes,
title: board?.title,
maxVotes: board?.maxVotes,
users: board?.users
});
};
const [data, setData] = useState<UpdateBoardType>(initialData);

// References
const dialogContainerRef = useRef<HTMLSpanElement>(null);
Expand All @@ -87,10 +88,8 @@ const BoardSettings = ({
updateBoard: { mutate }
} = useBoard({ autoFetchBoard: false });

const responsible = useMemo(
() => data.users?.find((user) => user.role === BoardUserRoles.RESPONSIBLE)?.user,
[data]
);
const responsible = data.users?.find((user) => user.role === BoardUserRoles.RESPONSIBLE)?.user;

// Use Form Hook
const methods = useForm<{ title: string; maxVotes?: number | null }>({
mode: 'onBlur',
Expand All @@ -105,6 +104,7 @@ const BoardSettings = ({
// Method to close dialog and reset switches state
const handleClose = () => {
setIsOpen(false);
setData(initialData);
setSwitchesState({
maxVotes: false,
responsible: false
Expand Down