Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make timezone optional for onboarding and user settings #3972

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ const UserSettingsPage = ({ user }: UserSettingsPageProps) => {

<div id="upgrade" className="flex flex-col gap-2">
<label className="flex flex-col w-full gap-2">
Time zone*
<Select onValueChange={(value) => setTimezone(value)} value={timezone} required>
Time zone
<Select onValueChange={(value) => setTimezone(value)} value={timezone}>
<SelectTrigger
selectIcon={
<div className="relative pr-4">
Expand All @@ -354,6 +354,7 @@ const UserSettingsPage = ({ user }: UserSettingsPageProps) => {
</SelectTrigger>

<SelectContent position="item-aligned" className="bg-white">
<SelectItem value={""}>Select timezone</SelectItem>
{timezones.map((timezone, index) => (
<SelectItem key={`timezone_${index}`} value={timezone.value}>
{timezone.text}
Expand Down
44 changes: 23 additions & 21 deletions pages/start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,7 @@ const LoginStep2: React.FC<LoginStep2Props> = ({ user }) => {
const [timezone, setTimezone] = useState("");
const [loading, setLoading] = useState(false);

useEffect(() => {
const userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const timezone = timezones.find((timezone) => timezone.utc.includes(userTimezone));
if (timezone) {
setTimezone(timezone.value);
}
}, []);

const handleUpdateTimezone = async () => {
const handleOnboarding = async (updateTimezone: boolean) => {
setLoading(true);
try {
const data = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/onboarding`, {
Expand All @@ -167,7 +159,7 @@ const LoginStep2: React.FC<LoginStep2Props> = ({ user }) => {
"Content-Type": "application/json",
Authorization: `Bearer ${sessionToken}`,
},
body: JSON.stringify({ interests: [], timezone }),
body: JSON.stringify({ interests: [], timezone: updateTimezone ? timezone : "" }),
});

if (data.ok) {
Expand Down Expand Up @@ -203,8 +195,7 @@ const LoginStep2: React.FC<LoginStep2Props> = ({ user }) => {
</div>

<div className="flex flex-col gap-2">
<label>Time zone*</label>
<Select onValueChange={(value) => setTimezone(value)} value={timezone} required>
<Select onValueChange={(value) => setTimezone(value)} value={timezone}>
<SelectTrigger
selectIcon={
<div className="relative pr-4">
Expand All @@ -217,6 +208,7 @@ const LoginStep2: React.FC<LoginStep2Props> = ({ user }) => {
</SelectTrigger>

<SelectContent position="item-aligned" className="bg-white">
<SelectItem value={""}>Select timezone</SelectItem>
{timezones.map((timezone, index) => (
<SelectItem key={index} value={timezone.value}>
{timezone.text}
Expand All @@ -225,16 +217,26 @@ const LoginStep2: React.FC<LoginStep2Props> = ({ user }) => {
</SelectContent>
</Select>
</div>
<Button
variant="primary"
onClick={() => handleOnboarding(true)}
className="justify-center w-full mt-4"
disabled={loading}
loading={loading}
>
Continue
</Button>

<Button
variant="primary"
onClick={() => handleOnboarding(false)}
className="justify-center w-full mt-4"
disabled={loading}
loading={loading}
>
Skip
</Button>
</div>
<Button
variant="primary"
onClick={handleUpdateTimezone}
className="justify-center w-full h-10 mt-3 md:mt-0"
disabled={loading || !timezone}
loading={loading}
>
Continue
</Button>
</div>
</>
);
Expand Down
Loading