fix: s-s rendered page is trying to access an unavailable component

This commit is contained in:
vidvidvid
2021-12-29 12:04:30 +01:00
committed by Alec LaLonde
parent b00fc2a7e8
commit f01abfce77
2 changed files with 19 additions and 30 deletions

View File

@@ -5,22 +5,24 @@ import { useUpdateProfileMutation } from 'graphql/autogen/types';
import { useUser } from 'lib/hooks';
import React, { useEffect, useState } from 'react';
export type SetupTimezoneProps = {
timeZone: string;
setTimeZone: React.Dispatch<React.SetStateAction<string>>;
};
export const SetupTimeZone: React.FC<SetupTimezoneProps> = ({
timeZone,
setTimeZone,
}) => {
export const SetupTimeZone: React.FC = () => {
const { onNextPress, nextButtonLabel } = useSetupFlow();
const [timeZone, setTimeZone] = useState<string>('');
const { user } = useUser();
const toast = useToast();
const [updateProfileRes, updateProfile] = useUpdateProfileMutation();
const [loading, setLoading] = useState(false);
useEffect(() => {
if (user?.player) {
const { player } = user;
if (player.timezone && !timeZone) {
setTimeZone(player.timezone);
}
}
}, [user, timeZone]);
const handleNextPress = async () => {
if (!user) return;

View File

@@ -1,9 +1,8 @@
import { SetupProfile } from 'components/Setup/SetupProfile';
import { SetupTimeZone } from 'components/Setup/SetupTimeZone';
import { SetupContextProvider } from 'contexts/SetupContext';
import { useUser } from 'lib/hooks';
import { InferGetStaticPropsType } from 'next';
import React, { useState } from 'react';
import React from 'react';
export const getStaticProps = async () => ({
props: {
@@ -13,23 +12,11 @@ export const getStaticProps = async () => ({
export type DefaultSetupProps = InferGetStaticPropsType<typeof getStaticProps>;
const TimeZoneSetup: React.FC<DefaultSetupProps> = () => {
const [timeZone, setTimeZone] = useState<string>('');
const { user } = useUser();
if (user?.player) {
const { player } = user;
if (player.timezone && !timeZone) {
setTimeZone(player.timezone);
}
}
return (
<SetupContextProvider>
<SetupProfile>
<SetupTimeZone timeZone={timeZone} setTimeZone={setTimeZone} />
</SetupProfile>
</SetupContextProvider>
);
};
const TimeZoneSetup: React.FC<DefaultSetupProps> = () => (
<SetupContextProvider>
<SetupProfile>
<SetupTimeZone />
</SetupProfile>
</SetupContextProvider>
);
export default TimeZoneSetup;