-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunnelContext.tsx
More file actions
59 lines (52 loc) · 1.74 KB
/
Copy pathFunnelContext.tsx
File metadata and controls
59 lines (52 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { createContext, ReactNode, useContext, useState } from 'react';
import { CreateEventRequest } from './event';
import { HostCreationRequest } from '../../host/model/host';
export interface FunnelState {
hostState: HostCreationRequest;
eventState: CreateEventRequest;
setHostState: React.Dispatch<React.SetStateAction<FunnelState['hostState']>>;
setEventState: React.Dispatch<React.SetStateAction<FunnelState['eventState']>>;
setHostChannelId: (hostChannelId: number) => void;
}
const FunnelContext = createContext<FunnelState | undefined>(undefined);
export const FunnelProvider = ({ children }: { children: ReactNode }) => {
const [hostState, setHostState] = useState<FunnelState['hostState']>({
profileImageUrl: '',
hostChannelName: '',
hostEmail: '',
channelDescription: '',
});
const [eventState, setEventState] = useState<FunnelState['eventState']>({
hostChannelId: 0,
title: '',
startDate: '',
endDate: '',
bannerImageUrl: '',
description: '',
referenceLinks: [],
onlineType: 'ONLINE',
address: '',
detailAddress: '',
locationLat: 37.5665,
locationLng: 126.978,
category: 'DEVELOPMENT_STUDY',
hashtags: [],
organizerEmail: '',
organizerPhoneNumber: '',
});
const setHostChannelId = (hostChannelId: number) => {
setEventState(prev => ({ ...prev, hostChannelId }));
};
return (
<FunnelContext.Provider value={{ hostState, eventState, setHostState, setEventState, setHostChannelId }}>
{children}
</FunnelContext.Provider>
);
};
export const useFunnelState = () => {
const context = useContext(FunnelContext);
if (!context) {
throw new Error('useFunnelState must be used within a FunnelProvider');
}
return context;
};