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 all commits
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
61 changes: 38 additions & 23 deletions pages/start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "c
import { timezones } from "lib/utils/timezones";
import { useFetchUser } from "lib/hooks/useFetchUser";
import { useFetchUserDevStats } from "lib/hooks/api/useFetchUserDevStats";
import { copyImageToClipboard } from "lib/utils/copy-to-clipboard";
import { toast } from "lib/hooks/useToast";
import { siteUrl } from "lib/utils/urls";

type StepKeys = "1" | "2" | "3";

Expand Down Expand Up @@ -151,15 +154,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 @@ -168,7 +163,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 @@ -204,8 +199,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 @@ -218,6 +212,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 @@ -226,16 +221,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 Expand Up @@ -281,10 +286,20 @@ const LoginStep3: React.FC<LoginStep3Props> = ({ user }) => {

<Button
variant="primary"
onClick={() => router.push(`/u/${username}/card`)}
onClick={() =>
copyImageToClipboard(siteUrl(`og-images/dev-card`, { username })).then((copied) => {
if (copied) {
setTimeout(() => {
toast({ description: "Copied to clipboard", variant: "success" });
}, 500);
} else {
toast({ description: "Error copying to clipboard", variant: "warning" });
}
})
}
className="justify-center w-full mt-4"
>
Go to Your DevCard
Share Your DevCard
</Button>

<Button
Expand Down
Loading