Skip to content

Commit

Permalink
feat: 알림 발송 API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokyeom committed Oct 14, 2024
1 parent e931706 commit d25d07e
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 22 deletions.
54 changes: 43 additions & 11 deletions src/components/alarmAdmin/CreateNewAlarmModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { useState, ChangeEvent } from 'react';
import { Button, Chip, SelectV2, TextArea, TextField } from '@sopt-makers/ui';
import 'react-datepicker/dist/react-datepicker.css';

import { Button, Chip, SelectV2, TextArea, TextField } from '@sopt-makers/ui';
import { ChangeEvent, useState } from 'react';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';

import ModalFooter from '@/components/common/modal/ModalFooter';
import ModalHeader from '@/components/common/modal/ModalHeader';
import { createReserveAlarm, sendAlarm } from '@/services/api/alarm';
import { ACTIVITY_GENERATION } from '@/utils/generation';

import LabeledComponent from './LabeledComponent';
import {
deepLinkOptions,
partOptions,
targetOptions,
timeOptions,
} from './selectOptions';
import {
AttachOptionButtonList,
AttachWrapper,
Expand All @@ -30,14 +39,8 @@ import {
StyledIconArrowUpRight,
textAreaCSS,
} from './style';
import {
deepLinkOptions,
partOptions,
targetOptions,
timeOptions,
} from './selectOptions';
import LabeledComponent from './LabeledComponent';
import { AttachOptionType, SendPartType, SendTargetType } from './type';
import { linkTypeMap, partMap, targetTypeMap } from './utils';

interface Props {
onClose: () => void;
Expand Down Expand Up @@ -172,7 +175,36 @@ function CreateNewAlarmModal(props: Props) {
};

// 발송 / 예약하기 버튼 눌렀을 때 API 요청 쏘는 함수
const handleClickCompleteButton = () => {};
const handleClickCompleteButton = async () => {
const commonPayload: AlarmData = {
createdGeneration: parseInt(ACTIVITY_GENERATION),
targetType: targetTypeMap[selectedTarget],
part: partMap[selectedPart],
category: 'NOTICE',
title: alarmTitle,
content: alarmDetail,
linkType: linkTypeMap[attachOption],
link: 'https://www.linkedin.com/in/brokyeom/',
};

console.log(commonPayload);

switch (sendType) {
case 'NOW':
await sendAlarm(commonPayload);
break;

case 'RESERVE':
const reservePayload: ReserveAlarmData = {
...commonPayload,
postDate: formatDate(selectedDate),
postTime: selectedTime,
};

await createReserveAlarm(reservePayload);
break;
}
};

return (
<StAlarmModalWrapper>
Expand Down
8 changes: 5 additions & 3 deletions src/components/alarmAdmin/CreateNewAlarmModal/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export type SendTargetType = '활동 회원' | 'CSV 첨부';
export type SendTargetType = '전체' | '활동 회원' | 'CSV 첨부';
export type requestTargetType = 'ALL' | 'ACTIVE' | 'CSV';

export type AttachOptionType = '첨부 안함' | '웹 링크' | '앱 내 딥링크';
export type requestLinkType = 'WEB' | 'APP' | null;

export interface ISendTargetOptions {
label: SendTargetType;
Expand All @@ -19,5 +23,3 @@ export interface ISendPartOptions {
label: SendPartType;
value: SendPartType;
}

export type AttachOptionType = '첨부 안함' | '웹 링크' | '앱 내 딥링크';
30 changes: 30 additions & 0 deletions src/components/alarmAdmin/CreateNewAlarmModal/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
AttachOptionType,
requestLinkType,
requestTargetType,
SendPartType,
SendTargetType,
} from './type';

export const partMap: Record<SendPartType, PART> = {
전체: 'ALL',
기획: 'PLAN',
디자인: 'DESIGN',
서버: 'SERVER',
iOS: 'IOS',
안드로이드: 'ANDROID',
: 'WEB',
'': 'ALL',
};

export const targetTypeMap: Record<SendTargetType, requestTargetType> = {
전체: 'ALL',
'활동 회원': 'ACTIVE',
'CSV 첨부': 'CSV',
};

export const linkTypeMap: Record<AttachOptionType, requestLinkType> = {
'첨부 안함': null,
'웹 링크': 'WEB',
'앱 내 딥링크': 'APP',
};
23 changes: 15 additions & 8 deletions src/services/api/alarm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { AxiosResponse } from 'axios';

import { client } from '@/services/api/client';

export const postNewAlarm = async (alarmData: PostAlarmData): Promise<void> => {
await client.post('/alarms', alarmData);
};

export const getAlarmList = async (generation: number): Promise<Alarm[]> => {
const { data }: AxiosResponse<{ data: { alarms: Alarm[] } }> =
await client.get(
Expand All @@ -15,12 +11,23 @@ export const getAlarmList = async (generation: number): Promise<Alarm[]> => {
return data.data.alarms;
};

export const sendAlarm = async (alarmId: number): Promise<boolean> => {
const { data }: AxiosResponse<{ success: boolean }> = await client.post(
export const sendAlarm = async (alarmData: AlarmData): Promise<any> => {
const { data }: AxiosResponse<any> = await client.post(
'/alarms/send',
{ alarmId },
alarmData,
);
return data.success;
return data;
};

export const createReserveAlarm = async (
alarmData: ReserveAlarmData,
): Promise<any> => {
const { data }: AxiosResponse<any> = await client.post(
'/alarms/schedule',
alarmData,
);

return data;
};

export const getAlarm = async (alarmId: number): Promise<AlarmDetail> => {
Expand Down
17 changes: 17 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ declare global {
content: string;
link?: string | null;
}

interface AlarmData {
createdGeneration: number;
title: string;
content: string;
category: 'NOTICE' | 'NEWS';
targetType: 'ALL' | 'ACTIVE' | 'CSV';
targetList?: Array<string>;
part?: PART;
linkType?: 'WEB' | 'APP' | null;
link?: string;
}

interface ReserveAlarmData extends AlarmData {
postDate: string;
postTime: string;
}
interface Alarm {
alarmId: number;
part: string | null;
Expand Down

0 comments on commit d25d07e

Please sign in to comment.