@kiwicom/smart-faq
Version:
59 lines (45 loc) • 1.18 kB
JavaScript
// @flow
import * as React from 'react';
const initialState = {
activeExtraInfoCategory: null,
};
export type ExtraInfoCategory = 'baggage' | 'boarding-passes';
type Props = {
children: React.Node,
};
export type State = {
activeExtraInfoCategory: ?ExtraInfoCategory,
};
export type Context = State & {
setExtraInfoCategory: (category: ?ExtraInfoCategory) => void,
};
export const categories = {
BAGGAGE: 'RkFRQ2F0ZWdvcnk6ODk',
BOARDING_PASS: 'RkFRQ2F0ZWdvcnk6ODQ',
};
export const ExtraInfoState: React.Context<Context> = React.createContext({
...initialState,
setExtraInfoCategory: () => {},
});
class ExtraInfoStateProvider extends React.Component<Props, Context> {
constructor(props: Props) {
super(props);
this.state = {
...initialState,
setExtraInfoCategory: this.setExtraInfoCategory,
};
}
setExtraInfoCategory = (category: ?ExtraInfoCategory) => {
this.setState({
activeExtraInfoCategory: category,
});
};
render() {
return (
<ExtraInfoState.Provider value={this.state}>
{this.props.children}
</ExtraInfoState.Provider>
);
}
}
export default ExtraInfoStateProvider;