Skip to content

Commit

Permalink
Merge pull request #158 from Make-A-Wish-Sopt/feature/156-wishesBtn
Browse files Browse the repository at this point in the history
Feature/156 wishes btn
  • Loading branch information
myeongheonhong authored Dec 19, 2023
2 parents 0762b6d + 5f30116 commit 98f9236
Show file tree
Hide file tree
Showing 41 changed files with 766 additions and 863 deletions.
28 changes: 16 additions & 12 deletions api/wishes/wishesAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import PATH from '../../constant/path';
import { client } from '../common/axios';
import axios from 'axios';
import { SiteDataType } from '@/types/siteDataType';
import { AccountInfoType, WishesDataInputType } from '@/types/common/input/wishesInput';
import {
AccountInfoType,
BankInfoInputsType,
WishesDataInputType,
} from '@/types/common/input/wishesInput';
import { UseFormReturn } from 'react-hook-form';

export const createWishesLink = async (wishesData: WishesDataInputType) => {
const accessToken = localStorage.getItem('accessToken');
const ACCESS_TOKEN = localStorage.getItem('accessToken');

export const createWishesLink = async (wishesData: WishesDataInputType) => {
const data = await client.post(
`${PATH.API}/${PATH.V1}/${PATH.WISHES}`,
{
Expand All @@ -21,30 +26,29 @@ export const createWishesLink = async (wishesData: WishesDataInputType) => {
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
},
);
return data;
};

export const editUserAccount = async (accountInfo: AccountInfoType, phone: string) => {
const accessToken = localStorage.getItem('accessToken');

export const editUserAccount = async (
methods: UseFormReturn<BankInfoInputsType, any, undefined>,
) => {
const data = await client.put(
`${PATH.API}/${PATH.V1}/${PATH.USER}/${PATH.ACCOUNT}`,
{
accountInfo: {
name: accountInfo.name,
bank: accountInfo.bankName,
account: accountInfo.account,
name: methods.getValues('name'),
bank: methods.getValues('bankName'),
account: methods.getValues('account'),
},
phone,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
},
);
Expand Down
13 changes: 7 additions & 6 deletions components/common/alertTextBox.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { ReactNode } from 'react';
import { AlertIc } from '@/public/assets/icons';
import { AlertSuccessIc, AlertWarningIc } from '@/public/assets/icons';
import theme from '@/styles/theme';
import styled from 'styled-components';
import Image from 'next/image';

interface AlertTextBoxProps {
alertSuccess?: boolean;
children: ReactNode;
}

export default function AlertTextBox(props: AlertTextBoxProps) {
const { children } = props;
const { alertSuccess, children } = props;

return (
<Styled.Container>
<Image src={AlertIc} alt="경고" />
<Styled.Text>{children}</Styled.Text>
<Image src={alertSuccess ? AlertSuccessIc : AlertWarningIc} alt="알림 아이콘" />
<Styled.Text alertSuccess={alertSuccess}>{children}</Styled.Text>
</Styled.Container>
);
}
Expand All @@ -25,9 +26,9 @@ const Styled = {
align-items: center;
margin-top: 1rem;
`,
Text: styled.div`
Text: styled.span<{ alertSuccess?: boolean }>`
margin-left: 0.6rem;
${theme.fonts.body12};
color: ${theme.colors.warning_red};
color: ${(props) => (props.alertSuccess ? theme.colors.dark_blue : theme.colors.warning_red)};
`,
};
6 changes: 5 additions & 1 deletion components/common/box/imageBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const StyledImageBox = styled(StyledBox)<{ width?: number; height: number }>`
//ImageBox Style System
&.imageBox--textarea {
height: 16rem;
border-radius: 1rem;
padding: 1.4rem 1.2rem;
}
Expand All @@ -39,8 +41,10 @@ const StyledImageBox = styled(StyledBox)<{ width?: number; height: number }>`
justify-content: center;
align-items: center;
padding: 0;
border-radius: 1.6rem;
object-fit: cover;
overflow: hidden;
}
`;
13 changes: 4 additions & 9 deletions components/common/box/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ import styled, { CSSProperties } from 'styled-components';
interface BoxProps {
boxType?: BoxTypes;
colorSystem: ColorSystemType;
boxStyled?: CSSProperties;
children: React.ReactNode;
}

export default function Box(props: BoxProps) {
const { boxType, colorSystem, boxStyled, children } = props;
const { boxType, colorSystem, children } = props;

return (
<StyledBox className={`${colorSystem} ${boxType}`} style={boxStyled}>
{children}
</StyledBox>
);
return <StyledBox className={`${colorSystem} ${boxType}`}>{children}</StyledBox>;
}

type BoxSizeType = 'Small' | 'Half' | 'Large' | 'Image';
Expand All @@ -26,7 +21,7 @@ export const BoxSize: Record<BoxSizeType, CSSProperties> = {
height: '4.6rem',
},
Half: {
width: 'calc(100% / 2) - 0.5rem',
width: 'calc(100%/2)',
height: '5rem',
},
Large: {
Expand Down Expand Up @@ -59,7 +54,7 @@ export const StyledBox = styled.div`
}
// Color System
&.gary1_white {
&.gray1_white {
background-color: ${theme.colors.gray1};
color: ${theme.colors.white};
}
Expand Down
14 changes: 12 additions & 2 deletions components/common/box/inputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ interface InputBoxProps {
export default function InputBox(props: PropsWithChildren<InputBoxProps>) {
const { width, boxType, colorSystem, children } = props;

console.log(boxType);

return (
<StyledInputBox className={`${colorSystem} ${boxType}`} width={width}>
{children}
Expand All @@ -23,6 +21,8 @@ export default function InputBox(props: PropsWithChildren<InputBoxProps>) {
}

const StyledInputBox = styled(StyledBox)<{ width?: string }>`
height: 5rem;
padding: 1rem 1rem 1rem 1.2rem;
border: 0.1rem solid ${theme.colors.main_blue};
border-radius: 1rem;
Expand All @@ -39,6 +39,16 @@ const StyledInputBox = styled(StyledBox)<{ width?: string }>`
align-items: center;
}
&.inputBox--calendar {
width: 16rem;
display: flex;
justify-content: space-between;
align-items: center;
${theme.fonts.body14};
}
&.inputBox--custom {
width: ${(props) => props.width};
height: 5rem;
Expand Down
3 changes: 2 additions & 1 deletion components/common/box/itemImageBox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Image from 'next/image';
import ImageBox from './imageBox';
import styled from 'styled-components';

interface ItemImageBoxProps {
src: string;
Expand All @@ -10,7 +11,7 @@ export default function ItemImageBox(props: ItemImageBoxProps) {
const { src, alt } = props;
return (
<ImageBox boxType="imageBox--image" colorSystem="white_mainBlue">
<Image src={src} fill={true} alt={alt} />
<Image src={src} alt={alt} fill={true} sizes="(max-width: 768px)" objectFit="cover" />
</ImageBox>
);
}
50 changes: 50 additions & 0 deletions components/common/calendar/CalendarHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import styled from 'styled-components';
import { getMonth, getYear } from 'date-fns';
import { MONTHS } from '@/constant/dateList';


interface CalendarHeaderProps {
date: Date;
changeYear: (year: number) => void;
changeMonth: (month: number) => void;
}

export default function CalendarHeader(props: CalendarHeaderProps) {
const { date, changeYear, changeMonth } = props;

// 연도 range
const years = Array.from(
{ length: getYear(new Date()) + 6 - getYear(new Date()) },
(_, index) => getYear(new Date()) + index,
);

return (
<Styled.CalendarHeader>
<select value={getYear(date)} onChange={({ target: { value } }) => changeYear(Number(value))}>
{years.map((option: number) => (
<option key={option} value={option}>
{option}
</option>
))}
</select>
년 &emsp;
<select
value={MONTHS[getMonth(date)]}
onChange={({ target: { value } }) => changeMonth(MONTHS.indexOf(value))}
>
{MONTHS.map((option) => (
<option key={option} value={option}>
{option}
</option>
))}
</select>
</Styled.CalendarHeader>
);
}

const Styled = {
CalendarHeader: styled.div`
width: 100%;
`,
};
55 changes: 41 additions & 14 deletions components/common/calendar/calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,65 @@
import theme from '@/styles/theme';
import styled from 'styled-components';
import Image from 'next/image';
import CustomDatePicker from '../modal/CustomDatePicker';
import { ko } from 'date-fns/locale';
import InputBox from '../box/inputBox';
import styled from 'styled-components';
import theme from '@/styles/theme';
import { ColorSystemType } from '@/types/common/box/boxStyleType';
import { UseFormReturn } from 'react-hook-form';
import { WishesDataInputType } from '@/types/common/input/wishesInput';
import { CalendarGreyIc, CalendarIc } from '@/public/assets/icons';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';
import CalendarHeader from './CalendarHeader';
import { getDate } from '@/utils/common/getDate';

interface CalendarProps {
date: Date;
changeStartDate?: (value: Date) => void;
calendarIcon: any;
methods: UseFormReturn<WishesDataInputType, any, undefined>;
disable: boolean;
colorSystem: ColorSystemType;
readOnly: boolean;
}

export default function Calendar(props: CalendarProps) {
const { date, changeStartDate, calendarIcon, readOnly } = props;
const { date, methods, disable, colorSystem, readOnly } = props;

const handleChangeDate = (selectedDate: Date) => {
methods.setValue('startDate', selectedDate);
methods.setValue('endDate', getDate(selectedDate, 7));
};

return (
<InputBox boxType="inputBox--half" colorSystem="pastelBlue_gray2">
<Styled.CalendarWrapper>
<CustomDatePicker date={date} changeStartDate={changeStartDate} readOnly={readOnly} />
<Image src={calendarIcon} alt="캘린더 아이콘" />
</Styled.CalendarWrapper>
<InputBox boxType="inputBox--calendar" colorSystem={colorSystem}>
<Styled.Wrapper>
<DatePicker
renderCustomHeader={({ date, changeYear, changeMonth }) => (
<CalendarHeader date={date} changeYear={changeYear} changeMonth={changeMonth} />
)}
locale={ko}
dateFormat="yyyy.MM.dd"
selected={new Date(date)}
onChange={handleChangeDate}
minDate={new Date()}
selectsEnd
readOnly={readOnly}
className="react-datepicker__input-container"
/>
{/* <CustomDatePicker date={date} methods={methods} readOnly={readOnly} /> */}
</Styled.Wrapper>
<Image src={disable ? CalendarGreyIc : CalendarIc} alt="캘린더 아이콘" />
</InputBox>
);
}

const Styled = {
CalendarWrapper: styled.div`
Wrapper: styled.div`
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 100%;
${theme.fonts.body12};
cursor: pointer;
`,
};
32 changes: 19 additions & 13 deletions components/common/input/input.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
import theme from '@/styles/theme';
import { WishesDataInputType } from '@/types/common/input/wishesInput';
import { PropsWithChildren } from 'react';
import { UseFormRegisterReturn } from 'react-hook-form';
import { FieldError, UseFormRegisterReturn } from 'react-hook-form';
import styled from 'styled-components';
import InputBox from '../box/inputBox';
import { InputBoxTypes } from '@/types/common/box/boxStyleType';
import { CakesDataInputType } from '@/types/common/input/cakesInput';
import AlertTextBox from '../alertTextBox';

interface InputProps {
width?: string;
boxType?: InputBoxTypes;
placeholder?: string;
readOnly?: boolean;
register: UseFormRegisterReturn<keyof WishesDataInputType | keyof CakesDataInputType>;
errors?: FieldError;
}

export default function Input(props: PropsWithChildren<InputProps>) {
const { width, boxType, placeholder, readOnly, register, children } = props;
const { width, boxType, placeholder, readOnly, register, errors, children } = props;

return (
<InputBox
width={width}
boxType={boxType || 'inputBox--large'}
colorSystem="pastelBlue_darkBlue"
>
<StyledInput placeholder={placeholder} readOnly={readOnly} {...register} />
{children}
</InputBox>
<>
<InputBox
width={width}
boxType={boxType || 'inputBox--large'}
colorSystem="pastelBlue_darkBlue"
>
<StyledInput placeholder={placeholder} readOnly={readOnly} {...register} />
{children}
</InputBox>
{errors?.message && <AlertTextBox>{errors.message}</AlertTextBox>}
</>
);
}

const StyledInput = styled.input`
${theme.fonts.body12};
color: ${theme.colors.dark_blue};
export const StyledInput = styled.input`
width: 100%;
height: 100%;
${theme.fonts.body12};
color: ${theme.colors.dark_blue};
`;
Loading

0 comments on commit 98f9236

Please sign in to comment.