mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-13 10:37:36 +03:00
form changes and i18n
This commit is contained in:
parent
125b62748c
commit
14eb86e1f6
@ -3,6 +3,7 @@
|
|||||||
"user": "Username",
|
"user": "Username",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
|
"firstTimeLogin": "Trying to log in for the first time? Credentials are printed in the Frigate logs.",
|
||||||
"errors": {
|
"errors": {
|
||||||
"usernameRequired": "Username is required",
|
"usernameRequired": "Username is required",
|
||||||
"passwordRequired": "Password is required",
|
"passwordRequired": "Password is required",
|
||||||
|
|||||||
@ -22,14 +22,24 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { AuthContext } from "@/context/auth-context";
|
import { AuthContext } from "@/context/auth-context";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import useSWR from "swr";
|
||||||
|
import { LuExternalLink } from "react-icons/lu";
|
||||||
|
import { useDocDomain } from "@/hooks/use-doc-domain";
|
||||||
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
||||||
interface UserAuthFormProps extends React.HTMLAttributes<HTMLDivElement> {}
|
interface UserAuthFormProps extends React.HTMLAttributes<HTMLDivElement> {}
|
||||||
|
|
||||||
export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
|
export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
|
||||||
const { t } = useTranslation(["components/auth"]);
|
const { t } = useTranslation(["components/auth", "common"]);
|
||||||
|
const { getLocaleDocUrl } = useDocDomain();
|
||||||
const [isLoading, setIsLoading] = React.useState<boolean>(false);
|
const [isLoading, setIsLoading] = React.useState<boolean>(false);
|
||||||
const { login } = React.useContext(AuthContext);
|
const { login } = React.useContext(AuthContext);
|
||||||
|
|
||||||
|
// need to use local fetcher because useSWR default fetcher is not set up in this context
|
||||||
|
const fetcher = (path: string) => axios.get(path).then((res) => res.data);
|
||||||
|
const { data } = useSWR("/auth/first_time_login", fetcher);
|
||||||
|
const showFirstTimeLink = data?.admin_first_time_login === true;
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
user: z.string().min(1, t("form.errors.usernameRequired")),
|
user: z.string().min(1, t("form.errors.usernameRequired")),
|
||||||
password: z.string().min(1, t("form.errors.passwordRequired")),
|
password: z.string().min(1, t("form.errors.passwordRequired")),
|
||||||
@ -136,6 +146,24 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
{showFirstTimeLink && (
|
||||||
|
<Card className="mt-4 p-4 text-center text-sm">
|
||||||
|
<CardContent className="p-2">
|
||||||
|
<p className="mb-2 text-primary-variant">
|
||||||
|
{t("form.firstTimeLogin")}
|
||||||
|
</p>
|
||||||
|
<a
|
||||||
|
href={getLocaleDocUrl("configuration/authentication#onboarding")}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="inline-flex items-center text-primary"
|
||||||
|
>
|
||||||
|
{t("readTheDocumentation", { ns: "common" })}
|
||||||
|
<LuExternalLink className="ml-2 size-3" />
|
||||||
|
</a>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
<Toaster />
|
<Toaster />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user