Skip to content

Commit

Permalink
remove: useChangePrivate 삭제 후 폴더에 내장
Browse files Browse the repository at this point in the history
  • Loading branch information
esthel7 committed Jan 13, 2024
1 parent 33e44b8 commit 58ba828
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
1 change: 0 additions & 1 deletion front/src/hooks/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default as useLogout } from './useLogout';
export { default as useChangePrivate } from './useChangePrivate';
30 changes: 0 additions & 30 deletions front/src/hooks/useChangePrivate.tsx

This file was deleted.

27 changes: 22 additions & 5 deletions front/src/pages/Main/LockModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useRef, useEffect } from 'react';
import { createPortal } from 'react-dom';
import { useRecoilValue } from 'recoil';
import { useRecoilState } from 'recoil';
import styled from 'styled-components';
import { theme } from '@utils';
import { useChangePrivate } from '@hooks';
import { axios, theme } from '@utils';
import { SnowBallRecoil } from '@states';
import { useNavigate } from 'react-router-dom';

interface LockModalProps {
toast: [boolean, React.Dispatch<React.SetStateAction<boolean>>];
Expand Down Expand Up @@ -81,9 +81,9 @@ const MButton = styled.button`
`;

const LockModal = (props: LockModalProps) => {
const changePrivate = useChangePrivate();
const navigate = useNavigate();
const modalRef = useRef<HTMLDivElement>(null);
const { snowBallData } = useRecoilValue(SnowBallRecoil);
const [{ snowBallData }, setSnowBallBox] = useRecoilState(SnowBallRecoil);
const privateFlag = snowBallData.is_message_private;

useEffect(() => {
Expand All @@ -105,6 +105,23 @@ const LockModal = (props: LockModalProps) => {
};
}, []);

const changePrivate = async () => {
const newData = {
title: snowBallData.title,
is_message_private: !snowBallData.is_message_private
};

try {
const res = await axios.put(`/api/snowball/${snowBallData.id}`, newData);
const resData = Object.assign({}, snowBallData);
resData.is_message_private = res.data.is_message_private;
setSnowBallBox(prev => ({ ...prev, snowBallData: resData }));
} catch (err) {
console.log(err);
navigate('*');
}
};

const setPrivate = async () => {
props.set(false);
await changePrivate();
Expand Down

0 comments on commit 58ba828

Please sign in to comment.