fixing so much trouble
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
TRegisterRequest,
|
||||
TVerifyEmailRequest,
|
||||
} from '../../types/auth';
|
||||
import { SessionToken, SessionUser } from '@imphnen-frontend-service/utils';
|
||||
|
||||
import { TResponseError, TResponseMessage } from '../../types/common';
|
||||
|
||||
@@ -19,11 +18,6 @@ export const usePostLogin = (): UseMutationResult<
|
||||
return useMutation({
|
||||
mutationKey: ['post-login'],
|
||||
mutationFn: async (payload) => await postLogin(payload),
|
||||
onSuccess: (res) => {
|
||||
SessionUser.set(res.data.user);
|
||||
SessionToken.set(res.data.token);
|
||||
window.location.reload();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export const authLoginSchema = z.object({
|
||||
.min(1, 'Password tidak boleh kosong'),
|
||||
});
|
||||
|
||||
export const stepOneRegisterSchema = z
|
||||
export const authRegisterSchema = z
|
||||
.object({
|
||||
email: z
|
||||
.string({
|
||||
@@ -25,6 +25,12 @@ export const stepOneRegisterSchema = z
|
||||
})
|
||||
.min(1, 'Email tidak boleh kosong')
|
||||
.email('Email harus valid'),
|
||||
phone_number: z
|
||||
.string({
|
||||
required_error: 'Nomor telepon tidak boleh kosong',
|
||||
})
|
||||
.min(1, 'Nomor telepon tidak boleh kosong')
|
||||
.max(15, 'Nomor telepon tidak boleh lebih dari 15 digit'),
|
||||
fullname: z
|
||||
.string({
|
||||
required_error: 'Nama tidak boleh kosong',
|
||||
@@ -51,28 +57,3 @@ export const stepOneRegisterSchema = z
|
||||
message: 'Password dan Konfirmasi Password harus sama',
|
||||
path: ['confirm_password'],
|
||||
});
|
||||
|
||||
const stepTwoRegisterSchema = z.object({
|
||||
phone_number: z
|
||||
.string({
|
||||
required_error: 'Nomor telepon tidak boleh kosong',
|
||||
invalid_type_error: 'Nomor telepon harus berupa string',
|
||||
})
|
||||
.min(1, 'Nomor telepon tidak boleh kosong')
|
||||
.max(15, 'Nomor telepon tidak boleh lebih dari 15 karakter'),
|
||||
referral_code: z
|
||||
.string()
|
||||
.min(1, 'Kode referral tidak boleh kosong')
|
||||
.max(4, 'Kode referral tidak boleh lebih dari 4 karakter')
|
||||
.optional(),
|
||||
referred_by: z
|
||||
.string()
|
||||
.min(1, 'Kode referral tidak boleh kosong')
|
||||
.max(50, 'Kode referral tidak boleh lebih dari 50 karakter')
|
||||
.optional(),
|
||||
student_type: z.string(),
|
||||
});
|
||||
|
||||
export const authRegisterSchema = stepOneRegisterSchema.and(
|
||||
stepTwoRegisterSchema
|
||||
);
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
import { z } from 'zod';
|
||||
import { authLoginSchema, authRegisterSchema } from '../../schemas';
|
||||
import { TResponseDetail, TResponseMessage } from '../common';
|
||||
import { TUserItem } from '../users';
|
||||
|
||||
export type TLoginRequest = {
|
||||
email: string;
|
||||
password: string;
|
||||
export type TTokenItem = {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
};
|
||||
|
||||
export type TLoginResponse = {
|
||||
data: {
|
||||
token: {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
};
|
||||
user: TUserItem;
|
||||
};
|
||||
export type TLoginItem = {
|
||||
token?: TTokenItem;
|
||||
user?: TUserItem;
|
||||
};
|
||||
|
||||
export type TRegisterRequest = {
|
||||
email: string;
|
||||
fullname: string;
|
||||
password: string;
|
||||
phone_number: string;
|
||||
referral_code?: string;
|
||||
referred_by?: string;
|
||||
student_type: string;
|
||||
confirm_password: string;
|
||||
export type TLoginRequest = z.infer<typeof authLoginSchema>;
|
||||
export type TLoginResponse = TResponseDetail<TLoginItem>;
|
||||
|
||||
export type TRegisterRequest = z.infer<typeof authRegisterSchema>;
|
||||
export type TRegisterResponse = TResponseDetail<TResponseMessage>;
|
||||
|
||||
export type TVerifyOtpRequest = {
|
||||
otp: number;
|
||||
};
|
||||
|
||||
export type TVerifyEmailRequest = {
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
import { AxiosError } from 'axios';
|
||||
|
||||
export type TResponse<T = unknown> = {
|
||||
export type TMetaResponse = {
|
||||
page: number;
|
||||
per_page: number;
|
||||
total: number;
|
||||
};
|
||||
|
||||
export type TResponseDetail<T = unknown> = {
|
||||
data: T;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export type TResponseList<T = unknown> = {
|
||||
data: T[];
|
||||
meta: TMetaResponse;
|
||||
};
|
||||
|
||||
export type TResponseMessage = {
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import { TPermissionItem } from '../permissions';
|
||||
|
||||
export type TRoleItem = {
|
||||
export type TRoleDetailItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
permissions: TPermissionItem[];
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export type TRolesListItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
permissions_count: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
permissions: TPermissionItem[];
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TRoleItem } from '../roles';
|
||||
import { TRoleDetailItem } from '../roles';
|
||||
|
||||
export type TUserItem = {
|
||||
id: string;
|
||||
@@ -7,13 +7,7 @@ export type TUserItem = {
|
||||
email: string;
|
||||
fullname: string;
|
||||
gender: string;
|
||||
identity_number: string;
|
||||
is_active: boolean;
|
||||
is_profile_completed: boolean;
|
||||
phone_number: string;
|
||||
referral_code: string;
|
||||
referred_by: string;
|
||||
religion: string;
|
||||
student_type: string;
|
||||
role: TRoleItem;
|
||||
role: TRoleDetailItem;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user