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

feat/#294 : 건의사항 페이지 구현 #299

Merged
merged 3 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Home from '@pages/Home';
import MajorDecision from '@pages/MajorDecision';
import Map from '@pages/Map';
import My from '@pages/My';
import SuggestionPage from '@pages/Suggestion';
import Tip from '@pages/Tip';
import RouteChangeTracker from '@utils/routeChangeTracker';
import { Routes, Route } from 'react-router-dom';
Expand All @@ -27,6 +28,7 @@ const App = () => {
<Route path="/my" element={<My />} />
<Route path="/tip/:type" element={<Tip />} />
<Route path="/FAQ" element={<FAQPage />} />
<Route path="/suggestion" element={<SuggestionPage />} />
</Route>
<Route element={<OverlayProvider />}>
<Route path="/map" element={<Map />} />
Expand Down
18 changes: 18 additions & 0 deletions src/apis/suggestion/post-suggestion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import http from '@apis/http';
import { SERVER_URL } from '@config/index';

const postSuggestion = async (value: string | undefined) => {
await http.post(
`${SERVER_URL}/api/suggestion`,
{
content: value,
},
{
headers: {
'Content-Type': 'application/json',
},
},
);
};

export default postSuggestion;
79 changes: 79 additions & 0 deletions src/pages/Suggestion/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import postSuggestion from '@apis/suggestion/post-suggestion';
import Button from '@components/Common/Button';
import InformUpperLayout from '@components/InformUpperLayout';
import { MODAL_BUTTON_MESSAGE, MODAL_MESSAGE } from '@constants/modal-messages';
import PLCACEHOLDER_MESSAGES from '@constants/placeholder-message';
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import useModals, { modals } from '@hooks/useModals';
import { THEME } from '@styles/ThemeProvider/theme';
import React, { useRef, useState } from 'react';

const SuggestionPage = () => {
const { openModal, closeModal } = useModals();
const areaRef = useRef<HTMLTextAreaElement>(null);
const [isInValidInput, setIsInValidInput] = useState<boolean>(true);

const onChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
if (!e.currentTarget.value || e.currentTarget.value.length < 5) {
setIsInValidInput(true);
return;
}
setIsInValidInput(false);
};

const onButtonClick = () => {
postSuggestion(areaRef.current?.value);
openModal<typeof modals.alert>(modals.alert, {
message: MODAL_MESSAGE.SUCCEED.POST_SUGGESTION,
buttonMessage: MODAL_BUTTON_MESSAGE.CONFIRM,
onClose: () => closeModal(modals.alert),
});
};

return (
<>
<InformUpperLayout>
<InformUpperLayout.InformTitle title="건의사항" />
<InformUpperLayout.InformSubTitle subTitle="부림이 서비스 관련 문의사항은 언제든지 건의사항에 남겨주세요!" />
</InformUpperLayout>
<StyledTextArea
minLength={5}
placeholder={PLCACEHOLDER_MESSAGES.SUGGESTION}
rows={10}
ref={areaRef}
onChange={onChange}
/>
<Button
disabled={isInValidInput}
onClick={onButtonClick}
css={css`
width: 50%;
margin: 0 auto;
`}
>
작성 완료
</Button>
</>
);
};

export default SuggestionPage;

const StyledTextArea = styled.textarea`
display: block;
padding: 20px;
width: 80%;
margin: 0 auto;
margin-bottom: 2rem;
line-height: 1.5;
resize: none;
font-size: 16px;
border-radius: 20px;
overflow-y: scoll;
border: 1px solid ${THEME.TEXT.GRAY};

&::placeholder {
color: ${THEME.TEXT.GRAY};
}
`;