on e692a23 help sign in
bridge/src/lib/flowCommand.js
49 lines 1.2 kB history raw
1import { useMemo } from 'react';
3// looks into the GET parameters and attempts to construct a "flow" object,
4// which would indicate bridge is to be used for one specific flow.
5// expects to find any of the following sets of parameters, varying by kind.
6//
7// ? kind = invite
8// & as = ~ship // who to send the invite as
9// & ship = ~ship // what planet to send as the invite
10// & email = ex@amp.le // email to send the invite code to
11//
13const COMMANDS = {
14 //
15};
17const useFlowCommand = () => {
18 const flow = useMemo(() => {
19 let flow = {};
21 window.location.search
22 .substr(1)
23 .split('&')
24 .forEach(arg => {
25 if ('' === arg) return;
26 const pam = arg.split('=');
27 flow[pam[0]] = pam.length <= 1 ? true : decodeURIComponent(pam[1]);
28 });
30 if (typeof flow === 'object') {
31 switch (flow.kind) {
32 default:
33 console.log('unrecognized kind of flow:', flow.kind);
34 // eslint-disable-next-line no-fallthrough
35 case undefined:
36 flow = null;
37 break;
38 }
39 } else {
40 flow = null;
41 }
43 return flow;
44 }, []);
46 return flow;
47};
49export { COMMANDS, useFlowCommand };