Merge pull request #2982 from bluewave-labs/feat/v2/theme
feat: add typography to theme, change UsePost return type
This commit is contained in:
3 files changed
+33
-8
No files matched your search
@@ -4,6 +4,11 @@ import type { SWRConfiguration } from "swr";
|
|||||||
import type { AxiosRequestConfig } from "axios";
|
import type { AxiosRequestConfig } from "axios";
|
||||||
import { get, post } from "@/Utils/ApiClient"; // your axios wrapper
|
import { get, post } from "@/Utils/ApiClient"; // your axios wrapper
|
||||||
|
|
||||||
|
export type ApiResponse = {
|
||||||
|
message: string;
|
||||||
|
data: any;
|
||||||
|
};
|
||||||
|
|
||||||
// Generic fetcher for GET requests
|
// Generic fetcher for GET requests
|
||||||
const fetcher = async <T,>(url: string, config?: AxiosRequestConfig) => {
|
const fetcher = async <T,>(url: string, config?: AxiosRequestConfig) => {
|
||||||
const res = await get<T>(url, config);
|
const res = await get<T>(url, config);
|
||||||
@@ -41,7 +46,8 @@ export const usePost = <B = any, R = any>(endpoint: string) => {
|
|||||||
const res = await post<R>(endpoint, body, config);
|
const res = await post<R>(endpoint, body, config);
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setError(err?.message ?? "Unknown error");
|
const errMsg = err?.response?.data?.msg || err.message || "An error occurred";
|
||||||
|
setError(errMsg);
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -8,28 +8,26 @@ import { TextInput } from "@/Components/Inputs/TextInput/indexV2.tsx";
|
|||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { usePost } from "@/Hooks/v2/UseApi";
|
import { usePost } from "@/Hooks/v2/UseApi";
|
||||||
|
import type { ApiResponse } from "@/Hooks/v2/UseApi";
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
email: z.email("Invalid email address"),
|
email: z.email("Invalid email address"),
|
||||||
password: z.string().min(6, "Password must be at least 6 characters"),
|
password: z.string().min(6, "Password must be at least 6 characters"),
|
||||||
});
|
});
|
||||||
|
|
||||||
type FormData = z.infer<typeof schema>;
|
type FormData = z.infer<typeof schema>;
|
||||||
type LoginData = {
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { post, loading, error } = usePost<FormData, LoginData>("/auth/login");
|
const { post, loading, error } = usePost<FormData, ApiResponse>("/auth/login");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
control,
|
control,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<FormData>({
|
} = useForm<FormData>({
|
||||||
resolver: zodResolver(schema), // ⬅️ connect Zod
|
resolver: zodResolver(schema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
@@ -39,7 +37,7 @@ const Login = () => {
|
|||||||
const onSubmit = async (data: FormData) => {
|
const onSubmit = async (data: FormData) => {
|
||||||
const result = await post(data);
|
const result = await post(data);
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log("Login successful:", result);
|
console.log(result.message);
|
||||||
} else {
|
} else {
|
||||||
console.error("Login failed:", error);
|
console.error("Login failed:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,27 @@ export const theme = (mode: string, palette: any) =>
|
|||||||
typography: {
|
typography: {
|
||||||
fontFamily: fontFamilyPrimary,
|
fontFamily: fontFamilyPrimary,
|
||||||
fontSize: typographyLevels.base,
|
fontSize: typographyLevels.base,
|
||||||
|
h1: {
|
||||||
|
fontSize: typographyLevels.xl,
|
||||||
|
color: palette.primary.contrastText,
|
||||||
|
fontWeight: 500,
|
||||||
|
},
|
||||||
|
h2: {
|
||||||
|
fontSize: typographyLevels.l,
|
||||||
|
color: palette.primary.contrastTextSecondary,
|
||||||
|
fontWeight: 400,
|
||||||
|
},
|
||||||
|
|
||||||
|
body1: {
|
||||||
|
fontSize: typographyLevels.m,
|
||||||
|
color: palette.primary.contrastTextTertiary,
|
||||||
|
fontWeight: 400,
|
||||||
|
},
|
||||||
|
body2: {
|
||||||
|
fontSize: typographyLevels.s,
|
||||||
|
color: palette.primary.contrastTextTertiary,
|
||||||
|
fontWeight: 400,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
Reference in new issue
Block a user