2026-01-27 08:24:22 +00:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
* See the LICENSE file for details.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-05-08 17:31:20 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
refactor: migrate space icons to @makeplane/propel (#9729)
* refactor: migrate space icons to @makeplane/propel
Replace confirmed icon symbols in apps/space with their audited
@makeplane/propel/icons targets. Unresolved symbols (StateGroupIcon,
PriorityIcon, PlaneLockup, PlaneLogo, Circle, CircleDashed, SignalHigh)
stay on their existing imports.
Propel icons paint with fill rather than stroke, so stroke-placeholder
classes become text-placeholder to preserve the rendered color. Lucide
size props become explicit width/height, and one chevron gains an
explicit height because Propel defaults to 1em where the legacy
IconWrapper defaulted to 16.
CycleGroupIcon is deliberately not migrated: it dispatches a different
glyph and color per cycle status, which CyclesOutline cannot express.
* fix: address icon migration review on space
Drop strokeWidth from Propel icons. The generated glyphs paint with
fill="currentColor", so the prop reached the svg and changed nothing;
keeping it implied a control that no longer exists.
Wrap the password and email-clear icon click targets in buttons. These
already carried onClick directly on the icon, but Propel bakes
aria-hidden="true" onto the svg, so the migration also hid them from
assistive tech. The buttons restore an accessible name and put the
controls in the tab order, matching the pattern email.tsx already uses.
2026-09-02 15:06:06 +00:00
|
|
|
import { CloseCircleOutline, TickCircleOutline } from "@makeplane/propel/icons";
|
2025-01-11 09:46:11 +00:00
|
|
|
// plane imports
|
2024-12-04 08:54:53 +00:00
|
|
|
import { API_BASE_URL } from "@plane/constants";
|
2025-09-30 10:01:00 +00:00
|
|
|
import { Button } from "@plane/propel/button";
|
2025-01-11 09:46:11 +00:00
|
|
|
import { AuthService } from "@plane/services";
|
2025-09-30 10:01:00 +00:00
|
|
|
import { Input, Spinner } from "@plane/ui";
|
2024-05-08 17:31:20 +00:00
|
|
|
// hooks
|
|
|
|
|
import useTimer from "@/hooks/use-timer";
|
|
|
|
|
// types
|
2024-05-16 11:47:04 +00:00
|
|
|
import { EAuthModes } from "@/types/auth";
|
2024-05-08 17:31:20 +00:00
|
|
|
|
2024-05-16 11:47:04 +00:00
|
|
|
// services
|
|
|
|
|
const authService = new AuthService();
|
|
|
|
|
|
|
|
|
|
type TAuthUniqueCodeForm = {
|
2024-05-08 17:31:20 +00:00
|
|
|
mode: EAuthModes;
|
2024-05-16 11:47:04 +00:00
|
|
|
email: string;
|
2024-05-17 08:57:49 +00:00
|
|
|
nextPath: string | undefined;
|
2024-05-08 17:31:20 +00:00
|
|
|
handleEmailClear: () => void;
|
2024-05-16 11:47:04 +00:00
|
|
|
generateEmailUniqueCode: (email: string) => Promise<{ code: string } | undefined>;
|
2024-05-08 17:31:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type TUniqueCodeFormValues = {
|
|
|
|
|
email: string;
|
|
|
|
|
code: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const defaultValues: TUniqueCodeFormValues = {
|
|
|
|
|
email: "",
|
|
|
|
|
code: "",
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-20 12:09:40 +00:00
|
|
|
export function AuthUniqueCodeForm(props: TAuthUniqueCodeForm) {
|
2024-05-17 08:57:49 +00:00
|
|
|
const { mode, email, nextPath, handleEmailClear, generateEmailUniqueCode } = props;
|
2024-05-16 11:47:04 +00:00
|
|
|
// derived values
|
|
|
|
|
const defaultResetTimerValue = 5;
|
2024-05-08 17:31:20 +00:00
|
|
|
// states
|
|
|
|
|
const [uniqueCodeFormData, setUniqueCodeFormData] = useState<TUniqueCodeFormValues>({ ...defaultValues, email });
|
|
|
|
|
const [isRequestingNewCode, setIsRequestingNewCode] = useState(false);
|
|
|
|
|
const [csrfToken, setCsrfToken] = useState<string | undefined>(undefined);
|
|
|
|
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
|
|
|
// timer
|
2024-05-16 11:47:04 +00:00
|
|
|
const { timer: resendTimerCode, setTimer: setResendCodeTimer } = useTimer(0);
|
2024-05-08 17:31:20 +00:00
|
|
|
|
|
|
|
|
const handleFormChange = (key: keyof TUniqueCodeFormValues, value: string) =>
|
|
|
|
|
setUniqueCodeFormData((prev) => ({ ...prev, [key]: value }));
|
|
|
|
|
|
2024-05-16 11:47:04 +00:00
|
|
|
const generateNewCode = async (email: string) => {
|
|
|
|
|
try {
|
|
|
|
|
setIsRequestingNewCode(true);
|
|
|
|
|
const uniqueCode = await generateEmailUniqueCode(email);
|
|
|
|
|
setResendCodeTimer(defaultResetTimerValue);
|
|
|
|
|
handleFormChange("code", uniqueCode?.code || "");
|
|
|
|
|
setIsRequestingNewCode(false);
|
|
|
|
|
} catch {
|
|
|
|
|
setResendCodeTimer(0);
|
|
|
|
|
console.error("Error while requesting new code");
|
|
|
|
|
setIsRequestingNewCode(false);
|
|
|
|
|
}
|
2024-05-08 17:31:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (csrfToken === undefined)
|
|
|
|
|
authService.requestCSRFToken().then((data) => data?.csrf_token && setCsrfToken(data.csrf_token));
|
|
|
|
|
}, [csrfToken]);
|
|
|
|
|
|
|
|
|
|
const isRequestNewCodeDisabled = isRequestingNewCode || resendTimerCode > 0;
|
|
|
|
|
const isButtonDisabled = isRequestingNewCode || !uniqueCodeFormData.code || isSubmitting;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<form
|
|
|
|
|
className="mt-5 space-y-4"
|
|
|
|
|
method="POST"
|
|
|
|
|
action={`${API_BASE_URL}/auth/spaces/${mode === EAuthModes.SIGN_IN ? "magic-sign-in" : "magic-sign-up"}/`}
|
|
|
|
|
onSubmit={() => setIsSubmitting(true)}
|
|
|
|
|
onError={() => setIsSubmitting(false)}
|
|
|
|
|
>
|
|
|
|
|
<input type="hidden" name="csrfmiddlewaretoken" value={csrfToken} />
|
2024-05-16 11:47:04 +00:00
|
|
|
<input type="hidden" value={uniqueCodeFormData.email} name="email" />
|
2024-05-17 08:57:49 +00:00
|
|
|
<input type="hidden" value={nextPath} name="next_path" />
|
2024-05-08 17:31:20 +00:00
|
|
|
<div className="space-y-1">
|
2025-12-12 15:20:14 +00:00
|
|
|
<label className="text-13 font-medium text-tertiary" htmlFor="email">
|
2024-05-08 17:31:20 +00:00
|
|
|
Email
|
|
|
|
|
</label>
|
2026-03-02 15:10:50 +00:00
|
|
|
<div className={`relative flex items-center rounded-md border border-subtle bg-surface-1`}>
|
2024-05-08 17:31:20 +00:00
|
|
|
<Input
|
|
|
|
|
id="email"
|
|
|
|
|
name="email"
|
|
|
|
|
type="email"
|
|
|
|
|
value={uniqueCodeFormData.email}
|
|
|
|
|
onChange={(e) => handleFormChange("email", e.target.value)}
|
|
|
|
|
placeholder="name@company.com"
|
2026-03-02 15:10:50 +00:00
|
|
|
className={`h-10 w-full border-0 disable-autofill-style placeholder:text-placeholder`}
|
2026-02-16 19:13:35 +00:00
|
|
|
autoComplete="off"
|
2024-05-08 17:31:20 +00:00
|
|
|
disabled
|
|
|
|
|
/>
|
|
|
|
|
{uniqueCodeFormData.email.length > 0 && (
|
refactor: migrate space icons to @makeplane/propel (#9729)
* refactor: migrate space icons to @makeplane/propel
Replace confirmed icon symbols in apps/space with their audited
@makeplane/propel/icons targets. Unresolved symbols (StateGroupIcon,
PriorityIcon, PlaneLockup, PlaneLogo, Circle, CircleDashed, SignalHigh)
stay on their existing imports.
Propel icons paint with fill rather than stroke, so stroke-placeholder
classes become text-placeholder to preserve the rendered color. Lucide
size props become explicit width/height, and one chevron gains an
explicit height because Propel defaults to 1em where the legacy
IconWrapper defaulted to 16.
CycleGroupIcon is deliberately not migrated: it dispatches a different
glyph and color per cycle status, which CyclesOutline cannot express.
* fix: address icon migration review on space
Drop strokeWidth from Propel icons. The generated glyphs paint with
fill="currentColor", so the prop reached the svg and changed nothing;
keeping it implied a control that no longer exists.
Wrap the password and email-clear icon click targets in buttons. These
already carried onClick directly on the icon, but Propel bakes
aria-hidden="true" onto the svg, so the migration also hid them from
assistive tech. The buttons restore an accessible name and put the
controls in the tab order, matching the pattern email.tsx already uses.
2026-09-02 15:06:06 +00:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
aria-label="Clear email"
|
|
|
|
|
className="absolute right-3 hover:cursor-pointer"
|
2024-06-13 09:20:36 +00:00
|
|
|
onClick={handleEmailClear}
|
refactor: migrate space icons to @makeplane/propel (#9729)
* refactor: migrate space icons to @makeplane/propel
Replace confirmed icon symbols in apps/space with their audited
@makeplane/propel/icons targets. Unresolved symbols (StateGroupIcon,
PriorityIcon, PlaneLockup, PlaneLogo, Circle, CircleDashed, SignalHigh)
stay on their existing imports.
Propel icons paint with fill rather than stroke, so stroke-placeholder
classes become text-placeholder to preserve the rendered color. Lucide
size props become explicit width/height, and one chevron gains an
explicit height because Propel defaults to 1em where the legacy
IconWrapper defaulted to 16.
CycleGroupIcon is deliberately not migrated: it dispatches a different
glyph and color per cycle status, which CyclesOutline cannot express.
* fix: address icon migration review on space
Drop strokeWidth from Propel icons. The generated glyphs paint with
fill="currentColor", so the prop reached the svg and changed nothing;
keeping it implied a control that no longer exists.
Wrap the password and email-clear icon click targets in buttons. These
already carried onClick directly on the icon, but Propel bakes
aria-hidden="true" onto the svg, so the migration also hid them from
assistive tech. The buttons restore an accessible name and put the
controls in the tab order, matching the pattern email.tsx already uses.
2026-09-02 15:06:06 +00:00
|
|
|
tabIndex={-1}
|
|
|
|
|
>
|
|
|
|
|
<CloseCircleOutline className="h-5 w-5 text-placeholder" />
|
|
|
|
|
</button>
|
2024-05-08 17:31:20 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-05-16 11:47:04 +00:00
|
|
|
|
2024-05-08 17:31:20 +00:00
|
|
|
<div className="space-y-1">
|
2025-12-12 15:20:14 +00:00
|
|
|
<label className="text-13 font-medium text-tertiary" htmlFor="code">
|
2024-05-08 17:31:20 +00:00
|
|
|
Unique code
|
|
|
|
|
</label>
|
|
|
|
|
<Input
|
|
|
|
|
name="code"
|
|
|
|
|
value={uniqueCodeFormData.code}
|
|
|
|
|
onChange={(e) => handleFormChange("code", e.target.value)}
|
2025-12-01 13:26:14 +00:00
|
|
|
placeholder="123456"
|
2026-03-02 15:10:50 +00:00
|
|
|
className="h-10 w-full border border-subtle !bg-surface-1 pr-12 disable-autofill-style placeholder:text-placeholder"
|
2026-02-16 19:13:35 +00:00
|
|
|
autoComplete="off"
|
2024-05-08 17:31:20 +00:00
|
|
|
autoFocus
|
|
|
|
|
/>
|
2026-03-02 15:10:50 +00:00
|
|
|
<div className="flex w-full items-center justify-between px-1 pt-1 text-11">
|
2025-12-26 11:06:29 +00:00
|
|
|
<p className="flex items-center gap-1 font-medium text-success-primary">
|
refactor: migrate space icons to @makeplane/propel (#9729)
* refactor: migrate space icons to @makeplane/propel
Replace confirmed icon symbols in apps/space with their audited
@makeplane/propel/icons targets. Unresolved symbols (StateGroupIcon,
PriorityIcon, PlaneLockup, PlaneLogo, Circle, CircleDashed, SignalHigh)
stay on their existing imports.
Propel icons paint with fill rather than stroke, so stroke-placeholder
classes become text-placeholder to preserve the rendered color. Lucide
size props become explicit width/height, and one chevron gains an
explicit height because Propel defaults to 1em where the legacy
IconWrapper defaulted to 16.
CycleGroupIcon is deliberately not migrated: it dispatches a different
glyph and color per cycle status, which CyclesOutline cannot express.
* fix: address icon migration review on space
Drop strokeWidth from Propel icons. The generated glyphs paint with
fill="currentColor", so the prop reached the svg and changed nothing;
keeping it implied a control that no longer exists.
Wrap the password and email-clear icon click targets in buttons. These
already carried onClick directly on the icon, but Propel bakes
aria-hidden="true" onto the svg, so the migration also hid them from
assistive tech. The buttons restore an accessible name and put the
controls in the tab order, matching the pattern email.tsx already uses.
2026-09-02 15:06:06 +00:00
|
|
|
<TickCircleOutline height={12} width={12} />
|
2024-05-08 17:31:20 +00:00
|
|
|
Paste the code sent to your email
|
|
|
|
|
</p>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2024-05-16 11:47:04 +00:00
|
|
|
onClick={() => generateNewCode(uniqueCodeFormData.email)}
|
2024-05-08 17:31:20 +00:00
|
|
|
className={`${
|
|
|
|
|
isRequestNewCodeDisabled
|
2025-12-12 15:20:14 +00:00
|
|
|
? "text-placeholder"
|
|
|
|
|
: "font-medium text-accent-secondary hover:text-accent-secondary"
|
2024-05-08 17:31:20 +00:00
|
|
|
}`}
|
|
|
|
|
disabled={isRequestNewCodeDisabled}
|
|
|
|
|
>
|
|
|
|
|
{resendTimerCode > 0
|
|
|
|
|
? `Resend in ${resendTimerCode}s`
|
|
|
|
|
: isRequestingNewCode
|
|
|
|
|
? "Requesting new code"
|
|
|
|
|
: "Resend"}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-05-16 11:47:04 +00:00
|
|
|
|
|
|
|
|
<div className="space-y-2.5">
|
2025-12-12 15:20:14 +00:00
|
|
|
<Button type="submit" variant="primary" className="w-full" size="xl" disabled={isButtonDisabled}>
|
2024-05-16 11:47:04 +00:00
|
|
|
{isRequestingNewCode ? "Sending code" : isSubmitting ? <Spinner height="20px" width="20px" /> : "Continue"}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2024-05-08 17:31:20 +00:00
|
|
|
</form>
|
|
|
|
|
);
|
2025-11-20 12:09:40 +00:00
|
|
|
}
|