Files
TheGame/packages/web/components/Setup/SetupAvailability.tsx
Alec LaLonde 44c706761c Feature/add timezone frontend (#231)
* Added tz column

* Updated hasura permissions on new table

* Added new dependencies for working with timezones

* Added SetupTimeZone component

* Bumped spacetime-informal to use their types

* Extracted timezone computation into helper, added useMemo hook

* Re-added spacetime types
2020-12-24 23:28:12 -07:00

99 lines
2.4 KiB
TypeScript

import {
Input,
InputGroup,
InputLeftElement,
InputRightAddon,
MetaButton,
MetaHeading,
Text,
useToast,
} from '@metafam/ds';
import { FlexContainer } from 'components/Container';
import { useSetupFlow } from 'contexts/SetupContext';
import { useUpdateProfileMutation } from 'graphql/autogen/types';
import { useUser } from 'lib/hooks';
import React, { useEffect, useState } from 'react';
export const SetupAvailability: React.FC = () => {
const {
onNextPress,
nextButtonLabel,
availability,
setAvailability,
} = useSetupFlow();
const [invalid, setInvalid] = useState(false);
const { user } = useUser({ redirectTo: '/' });
const toast = useToast();
useEffect(() => {
const value = Number(availability);
setInvalid(value < 0 || value > 168);
}, [availability]);
const [updateProfileRes, updateProfile] = useUpdateProfileMutation();
const handleNextPress = async () => {
if (!user) return;
const { error } = await updateProfile({
playerId: user.id,
input: {
availability_hours: Number(availability)
}
});
if (error) {
// eslint-disable-next-line no-console
console.warn(error);
toast({
title: 'Error',
description: 'Unable to update availability. The octo is sad 😢',
status: 'error',
isClosable: true,
});
return;
}
onNextPress();
};
return (
<FlexContainer>
<MetaHeading mb={5} textAlign="center">
Availability
</MetaHeading>
<Text mb={10}>
What is your weekly availability for any kind of freelance work?
</Text>
<InputGroup borderColor="transparent" mb={10}>
<InputLeftElement>
<span role="img" aria-label="clock">
🕛
</span>
</InputLeftElement>
<Input
background="dark"
placeholder="40"
type="number"
value={availability}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setAvailability(e.target.value)
}
isInvalid={invalid}
/>
<InputRightAddon background="purpleBoxDark">hr/week</InputRightAddon>
</InputGroup>
<MetaButton
onClick={handleNextPress}
mt={10}
isDisabled={invalid}
isLoading={updateProfileRes.fetching}
loadingText="Saving"
>
{nextButtonLabel}
</MetaButton>
</FlexContainer>
);
};