Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
💄 Use responsive field rows on the security page (#2888)
Luke Vellaf07495e4f8db
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex e62bdbabd..aa0597dd2 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -123,6 +123,8 @@"changeNameInfo": "This will not affect any votes you have already made.","changePassword": "Change password","changePasswordDescription": "Update your password to keep your account secure",+ "changePasswordError": "Something went wrong. Please try again.",+ "changePasswordSettingHint": "Update your password to keep your account secure.","changeRole": "Change role","charactersRemaining": "{count, plural, one {# character remaining} other {# characters remaining}}","checkForConflicts": "Toggle which calendars to check for conflicts",@@ -675,6 +677,8 @@"seatsUpdatedAlertTitle": "Seats updated","seatUsage": "{usedSeats} of {totalSeats} seats used","security": "Security",+ "securityAuthentication": "Authentication",+ "securityAuthenticationDescription": "Manage how you sign in to your account","securityDescription": "Manage your account security and password settings","selectPlan": "Select plan:","selectPotentialDates": "Select potential dates or times for your event",@@ -686,6 +690,7 @@"setMaxAttendees": "Set max attendees","setPassword": "Set password","setPasswordSectionDescription": "Your account doesn't have a password yet. Set one to sign in with your email address.",+ "setPasswordSettingHint": "Your account doesn't have a password yet. Set one to sign in with your email address.","setPasswordTitle": "Set password","settingCalendarSelection": "Setting calendar selection...","settingDefaultCalendar": "Setting default calendar...",diff --git a/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-dialog.tsx b/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-dialog.tsxnew file mode 100644index 000000000..93d0e00d2--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-dialog.tsx@@ -0,0 +1,205 @@+"use client";+import { zodResolver } from "@hookform/resolvers/zod";+import { Button } from "@rallly/ui/button";+import {+ Dialog,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+ useDialog,+} from "@rallly/ui/dialog";+import { Field, FieldError, FieldGroup, FieldLabel } from "@rallly/ui/field";+import { Form } from "@rallly/ui/form";+import { toast } from "@rallly/ui/sonner";+import React from "react";+import { Controller, useForm } from "react-hook-form";+import * as z from "zod";+import { PasswordInput } from "@/components/password-input";+import { PasswordStrengthMeter } from "@/features/auth/components/password-strength-meter";+import { usePasswordValidationSchema } from "@/features/auth/schema";+import { Trans, useTranslation } from "@/i18n/client";+import { authClient } from "@/lib/auth-client";++function useChangePasswordSchema() {+ const { t } = useTranslation();+ const passwordValidation = usePasswordValidationSchema();++ return z+ .object({+ currentPassword: z+ .string()+ .min(+ 1,+ t("passwordRequired", { defaultValue: "Password is required" }),+ ),+ newPassword: passwordValidation,+ })+ .refine((data) => data.currentPassword !== data.newPassword, {+ message: t("passwordsMustBeDifferent", {+ defaultValue: "New password must be different from current password",+ }),+ path: ["newPassword"],+ });+}++export function ChangePasswordDialog({+ trigger,+}: {+ trigger: React.ReactElement;+}) {+ const dialog = useDialog();+ const currentPasswordId = React.useId();+ const newPasswordId = React.useId();+ const changePasswordSchema = useChangePasswordSchema();+ const form = useForm({+ defaultValues: {+ currentPassword: "",+ newPassword: "",+ },+ resolver: zodResolver(changePasswordSchema),+ });+ const { handleSubmit, formState } = form;+ const { t } = useTranslation();++ return (+ <Dialog+ {...dialog.dialogProps}+ onOpenChange={(open) => {+ dialog.dialogProps.onOpenChange(open);+ if (!open) {+ form.reset();+ }+ }}+ >+ <DialogTrigger render={trigger} />+ <DialogContent>+ <Form {...form}>+ <form+ onSubmit={handleSubmit(async (data) => {+ const res = await authClient.changePassword({+ currentPassword: data.currentPassword,+ newPassword: data.newPassword,+ revokeOtherSessions: true,+ });++ if (res.error) {+ switch (res.error.code) {+ case "INVALID_PASSWORD":+ form.setError("currentPassword", {+ message: t("passwordIncorrect", {+ defaultValue: "Current password is incorrect",+ }),+ });+ break;+ default:+ form.setError("root", {+ message:+ res.error.message ??+ t("changePasswordError", {+ defaultValue:+ "Something went wrong. Please try again.",+ }),+ });+ break;+ }+ return;+ }++ form.reset();+ dialog.dismiss();+ toast.success(+ t("passwordChangedSuccess", {+ defaultValue: "Your password has been changed successfully",+ }),+ );+ })}+ >+ <DialogHeader>+ <DialogTitle>+ <Trans i18nKey="changePassword" defaults="Change password" />+ </DialogTitle>+ <DialogDescription>+ <Trans+ i18nKey="changePasswordDescription"+ defaults="Update your password to keep your account secure"+ />+ </DialogDescription>+ </DialogHeader>++ <FieldGroup className="py-4">+ {formState.errors.root?.message ? (+ <FieldError>{formState.errors.root.message}</FieldError>+ ) : null}++ <Controller+ control={form.control}+ name="currentPassword"+ render={({ field, fieldState }) => (+ <Field>+ <FieldLabel htmlFor={currentPasswordId}>+ <Trans+ i18nKey="currentPassword"+ defaults="Current password"+ />+ </FieldLabel>+ <PasswordInput+ {...field}+ id={currentPasswordId}+ autoComplete="current-password"+ disabled={formState.isSubmitting}+ placeholder="••••••••"+ aria-invalid={fieldState.invalid}+ />+ <FieldError errors={[fieldState.error]} />+ </Field>+ )}+ />++ <Controller+ control={form.control}+ name="newPassword"+ render={({ field, fieldState }) => (+ <Field>+ <FieldLabel htmlFor={newPasswordId}>+ <Trans i18nKey="newPassword" defaults="New password" />+ </FieldLabel>+ <PasswordInput+ {...field}+ id={newPasswordId}+ autoComplete="new-password"+ disabled={formState.isSubmitting}+ placeholder="••••••••"+ aria-invalid={fieldState.invalid}+ />+ <PasswordStrengthMeter+ password={field.value}+ className="mt-2"+ />+ <FieldError errors={[fieldState.error]} />+ </Field>+ )}+ />+ </FieldGroup>++ <DialogFooter>+ <DialogClose render={<Button />}>+ <Trans i18nKey="cancel" defaults="Cancel" />+ </DialogClose>+ <Button+ type="submit"+ variant="primary"+ loading={formState.isSubmitting}+ >+ <Trans i18nKey="changePassword" defaults="Change password" />+ </Button>+ </DialogFooter>+ </form>+ </Form>+ </DialogContent>+ </Dialog>+ );+}diff --git a/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-form.tsx b/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-form.tsxdeleted file mode 100644index 1234ee75a..000000000--- a/apps/web/src/app/[locale]/(space)/settings/security/components/change-password-form.tsx+++ /dev/null@@ -1,158 +0,0 @@-"use client";-import { zodResolver } from "@hookform/resolvers/zod";-import { Button } from "@rallly/ui/button";-import {- Form,- FormControl,- FormField,- FormItem,- FormLabel,- FormMessage,-} from "@rallly/ui/form";-import { toast } from "@rallly/ui/sonner";-import { useForm } from "react-hook-form";-import * as z from "zod";-import { PasswordInput } from "@/components/password-input";-import { PasswordStrengthMeter } from "@/features/auth/components/password-strength-meter";-import { usePasswordValidationSchema } from "@/features/auth/schema";-import { Trans, useTranslation } from "@/i18n/client";-import { authClient } from "@/lib/auth-client";--function useChangePasswordSchema() {- const { t } = useTranslation();- const passwordValidation = usePasswordValidationSchema();-- return z- .object({- currentPassword: z- .string()- .min(- 1,- t("passwordRequired", { defaultValue: "Password is required" }),- ),- newPassword: passwordValidation,- })- .refine((data) => data.currentPassword !== data.newPassword, {- message: t("passwordsMustBeDifferent", {- defaultValue: "New password must be different from current password",- }),- path: ["newPassword"],- });-}--export function ChangePasswordForm() {- const changePasswordSchema = useChangePasswordSchema();- const form = useForm({- defaultValues: {- currentPassword: "",- newPassword: "",- },- resolver: zodResolver(changePasswordSchema),- });- const { handleSubmit, formState } = form;- const { t } = useTranslation();-- return (- <Form {...form}>- <form- onSubmit={handleSubmit(async (data) => {- const res = await authClient.changePassword({- currentPassword: data.currentPassword,- newPassword: data.newPassword,- revokeOtherSessions: true,- });-- if (res.error) {- switch (res.error.code) {- case "INVALID_PASSWORD":- form.setError("currentPassword", {- message: t("passwordIncorrect", {- defaultValue: "Current password is incorrect",- }),- });- break;- default:- form.setError("root", {- message: res.error.message,- });- break;- }- return;- }-- form.reset();- toast.success(- t("passwordChangedSuccess", {- defaultValue: "Your password has been changed successfully",- }),- );- })}- >- {form.formState.errors.root?.message && (- <FormMessage>{form.formState.errors.root.message}</FormMessage>- )}-- <div className="grid grid-cols-1 gap-4">- <FormField- control={form.control}- name="currentPassword"- render={({ field }) => (- <FormItem>- <FormLabel>- <Trans- i18nKey="currentPassword"- defaults="Current password"- />- </FormLabel>- <FormControl>- <PasswordInput- {...field}- autoComplete="current-password"- disabled={formState.isSubmitting}- placeholder="••••••••"- />- </FormControl>- <FormMessage />- </FormItem>- )}- />-- <FormField- control={form.control}- name="newPassword"- render={({ field }) => (- <FormItem>- <FormLabel>- <Trans i18nKey="newPassword" defaults="New password" />- </FormLabel>- <FormControl>- <PasswordInput- {...field}- autoComplete="new-password"- disabled={formState.isSubmitting}- placeholder="••••••••"- />- </FormControl>- <PasswordStrengthMeter- password={field.value}- className="mt-2"- />- <FormMessage />- </FormItem>- )}- />- </div>-- <div className="mt-6">- <Button- type="submit"- loading={formState.isSubmitting}- variant="primary"- >- <Trans i18nKey="changePassword" defaults="Change password" />- </Button>- </div>- </form>- </Form>- );-}diff --git a/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-dialog.tsx b/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-dialog.tsxnew file mode 100644index 000000000..33d64af91--- /dev/null+++ b/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-dialog.tsx@@ -0,0 +1,129 @@+"use client";+import { zodResolver } from "@hookform/resolvers/zod";+import { Button } from "@rallly/ui/button";+import {+ Dialog,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+ useDialog,+} from "@rallly/ui/dialog";+import { Field, FieldError, FieldGroup, FieldLabel } from "@rallly/ui/field";+import { Form } from "@rallly/ui/form";+import { toast } from "@rallly/ui/sonner";+import React from "react";+import { Controller, useForm } from "react-hook-form";+import * as z from "zod";+import { PasswordInput } from "@/components/password-input";+import { setPasswordAction } from "@/features/auth/actions";+import { PasswordStrengthMeter } from "@/features/auth/components/password-strength-meter";+import { usePasswordValidationSchema } from "@/features/auth/schema";+import { Trans, useTranslation } from "@/i18n/client";+import { useSafeAction } from "@/lib/safe-action/client";++export function SetupPasswordDialog({+ trigger,+}: {+ trigger: React.ReactElement;+}) {+ const dialog = useDialog();+ const passwordId = React.useId();+ const { t } = useTranslation();+ const passwordValidation = usePasswordValidationSchema();+ const form = useForm({+ defaultValues: { password: "" },+ resolver: zodResolver(z.object({ password: passwordValidation })),+ });+ const { formState } = form;++ const setPassword = useSafeAction(setPasswordAction, {+ onSuccess: () => {+ form.reset();+ dialog.dismiss();+ toast.success(+ t("passwordSetSuccess", {+ defaultValue: "Your password has been set successfully",+ }),+ );+ },+ });++ return (+ <Dialog+ {...dialog.dialogProps}+ onOpenChange={(open) => {+ dialog.dialogProps.onOpenChange(open);+ if (!open) {+ form.reset();+ }+ }}+ >+ <DialogTrigger render={trigger} />+ <DialogContent>+ <Form {...form}>+ <form+ onSubmit={form.handleSubmit(async (data) => {+ await setPassword.executeAsync({ password: data.password });+ })}+ >+ <DialogHeader>+ <DialogTitle>+ <Trans i18nKey="setPasswordTitle" defaults="Set password" />+ </DialogTitle>+ <DialogDescription>+ <Trans+ i18nKey="setPasswordSectionDescription"+ defaults="Your account doesn't have a password yet. Set one to sign in with your email address."+ />+ </DialogDescription>+ </DialogHeader>++ <FieldGroup className="py-4">+ <Controller+ control={form.control}+ name="password"+ render={({ field, fieldState }) => (+ <Field>+ <FieldLabel htmlFor={passwordId}>+ <Trans i18nKey="newPassword" defaults="New password" />+ </FieldLabel>+ <PasswordInput+ {...field}+ id={passwordId}+ autoComplete="new-password"+ disabled={formState.isSubmitting}+ placeholder="••••••••"+ aria-invalid={fieldState.invalid}+ />+ <PasswordStrengthMeter+ password={field.value}+ className="mt-2"+ />+ <FieldError errors={[fieldState.error]} />+ </Field>+ )}+ />+ </FieldGroup>++ <DialogFooter>+ <DialogClose render={<Button />}>+ <Trans i18nKey="cancel" defaults="Cancel" />+ </DialogClose>+ <Button+ type="submit"+ variant="primary"+ loading={formState.isSubmitting}+ >+ <Trans i18nKey="setPassword" defaults="Set password" />+ </Button>+ </DialogFooter>+ </form>+ </Form>+ </DialogContent>+ </Dialog>+ );+}diff --git a/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-form.tsx b/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-form.tsxdeleted file mode 100644index c3a1a183a..000000000--- a/apps/web/src/app/[locale]/(space)/settings/security/components/setup-password-form.tsx+++ /dev/null@@ -1,88 +0,0 @@-"use client";-import { zodResolver } from "@hookform/resolvers/zod";-import { Button } from "@rallly/ui/button";-import {- Form,- FormControl,- FormField,- FormItem,- FormLabel,- FormMessage,-} from "@rallly/ui/form";-import { toast } from "@rallly/ui/sonner";-import { useForm } from "react-hook-form";-import * as z from "zod";-import { PasswordInput } from "@/components/password-input";-import { setPasswordAction } from "@/features/auth/actions";-import { PasswordStrengthMeter } from "@/features/auth/components/password-strength-meter";-import { usePasswordValidationSchema } from "@/features/auth/schema";-import { Trans, useTranslation } from "@/i18n/client";-import { useSafeAction } from "@/lib/safe-action/client";--export function SetupPasswordForm() {- const { t } = useTranslation();- const passwordValidation = usePasswordValidationSchema();- const form = useForm({- defaultValues: { password: "" },- resolver: zodResolver(z.object({ password: passwordValidation })),- });- const { formState } = form;-- const setPassword = useSafeAction(setPasswordAction, {- onSuccess: () => {- form.reset();- toast.success(- t("passwordSetSuccess", {- defaultValue: "Your password has been set successfully",- }),- );- },- });-- return (- <Form {...form}>- <form- onSubmit={form.handleSubmit(async (data) => {- await setPassword.executeAsync({ password: data.password });- })}- >- <div className="grid grid-cols-1 gap-4">- <FormField- control={form.control}- name="password"- render={({ field }) => (- <FormItem>- <FormLabel>- <Trans i18nKey="newPassword" defaults="New password" />- </FormLabel>- <FormControl>- <PasswordInput- {...field}- autoComplete="new-password"- disabled={formState.isSubmitting}- placeholder="••••••••"- />- </FormControl>- <PasswordStrengthMeter- password={field.value}- className="mt-2"- />- <FormMessage />- </FormItem>- )}- />- </div>-- <div className="mt-6">- <Button- type="submit"- loading={formState.isSubmitting}- variant="primary"- >- <Trans i18nKey="setPassword" defaults="Set password" />- </Button>- </div>- </form>- </Form>- );-}diff --git a/apps/web/src/app/[locale]/(space)/settings/security/page.tsx b/apps/web/src/app/[locale]/(space)/settings/security/page.tsxindex e42779187..e0c61a361 100644--- a/apps/web/src/app/[locale]/(space)/settings/security/page.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/security/page.tsx@@ -1,5 +1,13 @@import { Alert, AlertDescription } from "@rallly/ui/alert";-import { InfoIcon } from "lucide-react";+import { Button } from "@rallly/ui/button";+import {+ Field,+ FieldContent,+ FieldDescription,+ FieldGroup,+ FieldTitle,+} from "@rallly/ui/field";+import { InfoIcon, KeyRoundIcon } from "lucide-react";import type { Metadata } from "next";import type { Params } from "@/app/[locale]/types";import {@@ -10,6 +18,7 @@ import {PageSectionHeader,PageSectionTitle,} from "@/components/page-layout";+import { SettingIcon } from "@/components/setting-icon";import {SettingsPage,SettingsPageContent,@@ -22,8 +31,8 @@ import { requireUser } from "@/features/user/loaders";import { Trans } from "@/i18n/client";import { getTranslation } from "@/i18n/server";import { isFeatureEnabled } from "@/lib/feature-flags/server";-import { ChangePasswordForm } from "./components/change-password-form";-import { SetupPasswordForm } from "./components/setup-password-form";+import { ChangePasswordDialog } from "./components/change-password-dialog";+import { SetupPasswordDialog } from "./components/setup-password-dialog";export default async function SecurityPage() {const user = await requireUser();@@ -49,44 +58,72 @@ export default async function SecurityPage() {<SettingsPageContent>{isEmailLoginEnabled ? (<PageSectionGroup>- {hasPassword ? (- <PageSection variant="card">- <PageSectionHeader>- <PageSectionTitle>- <Trans- i18nKey="changePassword"- defaults="Change password"- />- </PageSectionTitle>- <PageSectionDescription>- <Trans- i18nKey="changePasswordDescription"- defaults="Update your password to keep your account secure"- />- </PageSectionDescription>- </PageSectionHeader>- <PageSectionContent>- <ChangePasswordForm />- </PageSectionContent>- </PageSection>- ) : (- <PageSection variant="card">- <PageSectionHeader>- <PageSectionTitle>- <Trans i18nKey="setPasswordTitle" defaults="Set password" />- </PageSectionTitle>- <PageSectionDescription>- <Trans- i18nKey="setPasswordSectionDescription"- defaults="Your account doesn't have a password yet. Set one to sign in with your email address."- />- </PageSectionDescription>- </PageSectionHeader>- <PageSectionContent>- <SetupPasswordForm />- </PageSectionContent>- </PageSection>- )}+ <PageSection variant="card">+ <PageSectionHeader>+ <PageSectionTitle>+ <Trans+ i18nKey="securityAuthentication"+ defaults="Authentication"+ />+ </PageSectionTitle>+ <PageSectionDescription>+ <Trans+ i18nKey="securityAuthenticationDescription"+ defaults="Manage how you sign in to your account"+ />+ </PageSectionDescription>+ </PageSectionHeader>+ <PageSectionContent>+ <FieldGroup variant="divided">+ <Field orientation="responsive">+ <SettingIcon>+ <KeyRoundIcon />+ </SettingIcon>+ <FieldContent>+ <FieldTitle>+ <Trans i18nKey="password" defaults="Password" />+ </FieldTitle>+ <FieldDescription>+ {hasPassword ? (+ <Trans+ i18nKey="changePasswordSettingHint"+ defaults="Update your password to keep your account secure."+ />+ ) : (+ <Trans+ i18nKey="setPasswordSettingHint"+ defaults="Your account doesn't have a password yet. Set one to sign in with your email address."+ />+ )}+ </FieldDescription>+ </FieldContent>+ {hasPassword ? (+ <ChangePasswordDialog+ trigger={+ <Button>+ <Trans+ i18nKey="changePassword"+ defaults="Change password"+ />+ </Button>+ }+ />+ ) : (+ <SetupPasswordDialog+ trigger={+ <Button>+ <Trans+ i18nKey="setPassword"+ defaults="Set password"+ />+ </Button>+ }+ />+ )}+ </Field>+ </FieldGroup>+ </PageSectionContent>+ </PageSection></PageSectionGroup>) : (<Alert>diff --git a/apps/web/src/components/setting-icon.tsx b/apps/web/src/components/setting-icon.tsxnew file mode 100644index 000000000..d260c6c7c--- /dev/null+++ b/apps/web/src/components/setting-icon.tsx@@ -0,0 +1,18 @@+import type React from "react";++/**+ * Icon shown alongside a setting row's title and description.+ *+ * Distinct from `PageIcon`, which identifies a route. This is decoration for a+ * row within a page, so it carries no color or size variants and is hidden+ * once the row stacks vertically and the icon would sit above the text.+ */+export function SettingIcon({ children }: { children: React.ReactNode }) {+ return (+ <div className="@md/field-group:block hidden pr-2">+ <span className="inline-flex size-10 items-center justify-center rounded-lg bg-gray-100 text-gray-500 dark:bg-gray-400/10 dark:text-gray-400 [&_svg]:size-5">+ {children}+ </span>+ </div>+ );+}