Add settings UI to opt into db login mode

Just a cute lil thing on the homepage, not very obvious at all but easy to find if you're looking for it!
This commit is contained in:
Emi Matchu 2022-08-26 16:17:25 -07:00
parent 9982cbf93d
commit 5d8b62d499
3 changed files with 65 additions and 6 deletions

View file

@ -157,7 +157,7 @@ function UserNavBarSection() {
} }
function LoginButton() { function LoginButton() {
const authMode = useAuthModeFeatureFlag(); const [authMode] = useAuthModeFeatureFlag();
const { loginWithRedirect } = useAuth0(); const { loginWithRedirect } = useAuth0();
const { isOpen, onOpen, onClose } = useDisclosure(); const { isOpen, onOpen, onClose } = useDisclosure();

View file

@ -7,6 +7,9 @@ import {
Button, Button,
Center, Center,
Flex, Flex,
FormControl,
FormHelperText,
FormLabel,
HStack, HStack,
IconButton, IconButton,
Input, Input,
@ -15,7 +18,14 @@ import {
InputRightElement, InputRightElement,
Link as ChakraLink, Link as ChakraLink,
ListItem, ListItem,
Popover,
PopoverArrow,
PopoverBody,
PopoverCloseButton,
PopoverContent,
PopoverTrigger,
Skeleton, Skeleton,
Switch,
Textarea, Textarea,
Tooltip, Tooltip,
UnorderedList, UnorderedList,
@ -45,6 +55,7 @@ import SquareItemCard, {
SquareItemCardSkeleton, SquareItemCardSkeleton,
} from "./components/SquareItemCard"; } from "./components/SquareItemCard";
import WIPCallout from "./components/WIPCallout"; import WIPCallout from "./components/WIPCallout";
import { useAuthModeFeatureFlag } from "./components/useCurrentUser";
import HomepageSplashImg from "./images/homepage-splash.png"; import HomepageSplashImg from "./images/homepage-splash.png";
import FeedbackKikoImg from "./images/feedback-kiko.png"; import FeedbackKikoImg from "./images/feedback-kiko.png";
@ -679,6 +690,8 @@ function FeedbackFormContainer({ background, borderColor, children }) {
} }
function FeedbackFormPitch() { function FeedbackFormPitch() {
const [authMode, setAuthMode] = useAuthModeFeatureFlag();
return ( return (
<Flex direction="column" textAlign="left" opacity="0.9"> <Flex direction="column" textAlign="left" opacity="0.9">
<Box as="header">Hi friends! Welcome to the beta!</Box> <Box as="header">Hi friends! Welcome to the beta!</Box>
@ -720,7 +733,48 @@ function FeedbackFormPitch() {
Coming soon Coming soon
</Box> </Box>
<UnorderedList> <UnorderedList>
<ListItem>Better login system</ListItem> <ListItem>
<Popover>
<PopoverTrigger>
<Box tabIndex="0" textDecoration="underline" cursor="pointer">
Better login system
</Box>
</PopoverTrigger>
<PopoverContent>
<PopoverArrow />
<PopoverCloseButton />
<PopoverBody>
<FormControl>
<Flex>
<Box>
<FormLabel
htmlFor="hi-res-mode-setting"
fontSize="sm"
margin="0"
>
Experimental login mode
</FormLabel>
<FormHelperText marginTop="0" fontSize="xs">
Should be faster and easierhelp us try it out!
After turning this on, try logging in.
</FormHelperText>
</Box>
<Box width="2" />
<Switch
id="hi-res-mode-setting"
size="sm"
marginTop="0.1rem"
isChecked={authMode === "db"}
onChange={(e) =>
setAuthMode(e.target.checked ? "db" : "auth0")
}
/>
</Flex>
</FormControl>
</PopoverBody>
</PopoverContent>
</Popover>
</ListItem>
<ListItem>Making sure we're ready for the long-term</ListItem> <ListItem>Making sure we're ready for the long-term</ListItem>
<ListItem> <ListItem>
a lot of little things{" "} a lot of little things{" "}

View file

@ -11,7 +11,7 @@ const NOT_LOGGED_IN_USER = {
}; };
function useCurrentUser() { function useCurrentUser() {
const authMode = useAuthModeFeatureFlag(); const [authMode] = useAuthModeFeatureFlag();
const currentUserViaAuth0 = useCurrentUserViaAuth0({ const currentUserViaAuth0 = useCurrentUserViaAuth0({
isEnabled: authMode === "auth0", isEnabled: authMode === "auth0",
}); });
@ -165,7 +165,7 @@ function getUserInfoFromAuth0Data(user) {
*/ */
export function useLogout() { export function useLogout() {
const { logout: logoutWithAuth0 } = useAuth0(); const { logout: logoutWithAuth0 } = useAuth0();
const authMode = useAuthModeFeatureFlag(); const [authMode] = useAuthModeFeatureFlag();
const [sendLogoutMutation, { loading, error }] = useMutation( const [sendLogoutMutation, { loading, error }] = useMutation(
gql` gql`
@ -223,7 +223,10 @@ export function useAuthModeFeatureFlag() {
// default to `null` instead of "auth0", I want to be unambiguous that this // default to `null` instead of "auth0", I want to be unambiguous that this
// is the *absence* of a localStorage value, and not risk accidentally // is the *absence* of a localStorage value, and not risk accidentally
// setting this override value to auth0 on everyone's devices 😅) // setting this override value to auth0 on everyone's devices 😅)
let [savedValue] = useLocalStorage("DTIAuthModeFeatureFlag", null); let [savedValue, setSavedValue] = useLocalStorage(
"DTIAuthModeFeatureFlag",
null
);
useEffect(() => { useEffect(() => {
window.setAuthModeFeatureFlag = setAuthModeFeatureFlag; window.setAuthModeFeatureFlag = setAuthModeFeatureFlag;
@ -237,7 +240,9 @@ export function useAuthModeFeatureFlag() {
savedValue = null; savedValue = null;
} }
return savedValue || "auth0"; const value = savedValue || "auth0";
return [value, setSavedValue];
} }
/** /**