Skip to content

Commit

Permalink
feat : 배너 생성, 삭제, 리스트 조회 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
은지 committed Mar 14, 2024
1 parent 78286d5 commit 4bcf74c
Show file tree
Hide file tree
Showing 14 changed files with 760 additions and 151 deletions.
83 changes: 83 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@team-return/design-system": "^1.1.13",
"axios": "^1.3.4",
"file-saver": "^2.0.5",
"html2canvas": "^1.4.1",
"react": "^18.2.0",
"react-beautiful-dnd": "^13.1.1",
"react-cookie": "^4.1.1",
Expand Down
55 changes: 55 additions & 0 deletions src/Apis/Banners/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { MutationOptions, useMutation, useQuery } from 'react-query';
import { instance } from '../axios';

const router = '/banners';

export const useCreateBanners = (
banner_url: string,
banner_type: string,
start_date: string,
end_date: string,
options: MutationOptions
) => {
const data = {
banner_url,
banner_type,
start_date,
end_date,
};
return useMutation(async () => instance.post(`${router}`, data), {
...options,
});
};

export const useGetBannerList = (
is_opened: boolean,
options: MutationOptions
) => {
const params = {
is_opened,
};
return useMutation(
async () =>
instance.get(`${router}/teacher`, {
params: params,
}),
{
...options,
}
);
};

export const useDeleteBanner = (
banner_id: number,
options: MutationOptions
) => {
return useMutation(
async () => {
const { data } = await instance.delete(`${router}/${banner_id}`);
return data;
},
{
...options,
}
);
};
10 changes: 10 additions & 0 deletions src/Apis/Banners/request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface DateProps {
banner_url: string;
start_date: string;
end_date: string;
banner_type: string;
}

export interface BannerProps {
banner_id: number;
}
19 changes: 19 additions & 0 deletions src/Apis/Banners/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface BannerListProps {
banner_id: number;
banner_url: string;
start_date: string;
end_date: string;
banner_type: string;
}

export interface BannerListResponse {
banners: BannerListProps[];
}

export interface BannerNameType {
RECRUITMENT: string;
BOOKMARK: string;
NONE: string;
INTERNSHIP: string;
COMPANY: string;
}
3 changes: 3 additions & 0 deletions src/Assets/SVG/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 66 additions & 15 deletions src/Components/Banner/BannerDetail.tsx/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,73 @@
import * as _ from './style';
import banner from '../../../Assets/PNG/banner.png';
import { useEffect, useState } from 'react';
import { useGetBannerList } from '../../../Apis/Banners';
import { BannerListProps } from '../../../Apis/Banners/response';
import { BannerNameType } from '../../../Apis/Banners/response';
import deleteimg from '../../../Assets/SVG/delete.svg';
interface Props {
onDelete: (id: number) => void;
}

export function BannerDetail({ onDelete }: Props) {
const [banners, setBanners] = useState<BannerListProps[]>([]);
const [isOpen, setIsOpen] = useState<boolean>(true);

const BannersAPI = useGetBannerList(isOpen, {
onSuccess: (data: any) => {
setBanners(data.data.banners);
},
onError: () => {},
});
console.log(BannersAPI);

useEffect(() => {
if (isOpen) BannersAPI.mutate();
}, [isOpen]);

const BannerType = {
RECRUITMENT: '모집의뢰서',
BOOKMARK: '북마크',
NONE: '페이지 이동 안함',
INTERNSHIP: '체험형 현장실습 페이지',
COMPANY: '기업 상세 페이지',
};

Object.freeze(BannerType);

export function BannerDetail() {
return (
<_.Container>
<_.BannerImg src={banner} />
<_.Wrapper>
<_.TextWrapper>
<_.Text>이동 되는 페이지</_.Text>
<_.TextContent>체험형 현장실습</_.TextContent>
</_.TextWrapper>
<_.TextWrapper>
<_.Text>표시 기간</_.Text>
<_.TextContent>
2024년 2월 24일 ~ 2024년 2월 27일
</_.TextContent>
</_.TextWrapper>
</_.Wrapper>
{banners &&
banners.length > 0 &&
banners.map((banner, index) => (
<_.BannerDetails key={index}>
<_.BannerImg src={banner.banner_url} />
<_.DeleteBackground
onClick={() => {
onDelete(banner.banner_id);
}}
>
<_.deleteImg src={deleteimg} />
</_.DeleteBackground>
<_.Wrapper>
<_.TextWrapper>
<_.Text>이동 되는 페이지</_.Text>
<_.TextContent>
{
BannerType[
banner.banner_type as keyof BannerNameType
]
}
</_.TextContent>
</_.TextWrapper>
<_.TextWrapper>
<_.Text>표시 기간</_.Text>
<_.TextContent>
{banner.start_date} ~ {banner.end_date}
</_.TextContent>
</_.TextWrapper>
</_.Wrapper>
</_.BannerDetails>
))}
</_.Container>
);
}
25 changes: 25 additions & 0 deletions src/Components/Banner/BannerDetail.tsx/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,34 @@ import styled from 'styled-components';
export const Container = styled.div`
display: flex;
flex-direction: column;
gap: 36px;
`;

export const BannerDetails = styled.div`
display: flex;
flex-direction: column;
position: relative;
gap: 20px;
`;

export const DeleteBackground = styled.div`
position: absolute;
top: 15px;
right: 15px;
width: 36px;
height: 36px;
border-radius: 50px;
background: var(--primary-30, #0f4c82);
display: flex;
align-items: center;
justify-content: center;
`;

export const deleteImg = styled.img`
width: 32px;
height: 32px;
`;

export const Wrapper = styled.div`
width: 1000px;
display: flex;
Expand Down
Loading

0 comments on commit 4bcf74c

Please sign in to comment.