Merge pull request #180 from bipproduction/fix/bug/profile

Fix/bug/profile
This commit is contained in:
Bagasbanuna02
2024-12-11 14:00:56 +08:00
committed by GitHub
12 changed files with 43 additions and 25 deletions

View File

@@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
## [1.2.23](https://github.com/bipproduction/hipmi/compare/v1.2.22...v1.2.23) (2024-12-11)
## [1.2.22](https://github.com/bipproduction/hipmi/compare/v1.2.21...v1.2.22) (2024-12-10) ## [1.2.22](https://github.com/bipproduction/hipmi/compare/v1.2.21...v1.2.22) (2024-12-10)
## [1.2.21](https://github.com/bipproduction/hipmi/compare/v1.2.20...v1.2.21) (2024-12-09) ## [1.2.21](https://github.com/bipproduction/hipmi/compare/v1.2.20...v1.2.21) (2024-12-09)

View File

@@ -1,6 +1,6 @@
{ {
"name": "hipmi", "name": "hipmi",
"version": "1.2.22", "version": "1.2.23",
"private": true, "private": true,
"prisma": { "prisma": {
"seed": "npx tsx prisma/seed.ts --yes" "seed": "npx tsx prisma/seed.ts --yes"

View File

@@ -1,14 +1,12 @@
import EditProfile from "@/app_modules/katalog/profile/edit/view"; import EditProfile from "@/app_modules/katalog/profile/edit/view";
import { Profile_getOneProfileAndUserById } from "@/app_modules/katalog/profile/fun/get/get_one_user_profile"; import { Profile_getOneProfileAndUserById } from "@/app_modules/katalog/profile/fun/get/get_one_user_profile";
export default async function Page({ params }: { params: { id: string } }) { export default async function Page({ params }: { params: { id: string } }) {
let profileId = params.id let profileId = params.id;
const dataProfile = await Profile_getOneProfileAndUserById(profileId) const dataProfile = await Profile_getOneProfileAndUserById(profileId);
return ( return (
<> <>
{/* {JSON.stringify(data)} */}
<EditProfile data={dataProfile as any} /> <EditProfile data={dataProfile as any} />
</> </>
); );

View File

@@ -3,6 +3,8 @@
import { Button, FileButton } from "@mantine/core"; import { Button, FileButton } from "@mantine/core";
import { IconCamera } from "@tabler/icons-react"; import { IconCamera } from "@tabler/icons-react";
import { MainColor } from "../color"; import { MainColor } from "../color";
import { MAX_SIZE } from "../lib";
import { ComponentGlobal_NotifikasiPeringatan } from "../notif_global";
export function ComponentGlobal_ButtonUploadFileImage({ export function ComponentGlobal_ButtonUploadFileImage({
onSetFile, onSetFile,
@@ -19,8 +21,14 @@ export function ComponentGlobal_ButtonUploadFileImage({
new Blob([new Uint8Array(await files.arrayBuffer())]) new Blob([new Uint8Array(await files.arrayBuffer())])
); );
onSetFile(files); if (files.size > MAX_SIZE) {
onSetImage(buffer); ComponentGlobal_NotifikasiPeringatan(
"Ukuran file terlalu besar. Maksimal 2 MB."
);
} else {
onSetFile(files);
onSetImage(buffer);
}
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }

View File

@@ -0,0 +1,3 @@
import { MAX_SIZE } from "./max_size";
export { MAX_SIZE };

View File

@@ -0,0 +1,2 @@
// Maksimal ukuran file dalam byte (2 MB)
export const MAX_SIZE = 2 * 1024 * 1024; // 2 MB

View File

@@ -28,7 +28,7 @@ export function UIGlobal_ImagePreview({ fileId }: { fileId: string }) {
const [isImage, setIsImage] = useState<boolean | null>(null); const [isImage, setIsImage] = useState<boolean | null>(null);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const url = APIs.GET({ fileId: fileId }); const url = APIs.GET({ fileId: fileId, size: "500" });
useShallowEffect(() => { useShallowEffect(() => {
onLoadImage(); onLoadImage();

View File

@@ -9,15 +9,13 @@ import {
ComponentGlobal_NotifikasiGagal, ComponentGlobal_NotifikasiGagal,
ComponentGlobal_NotifikasiPeringatan, ComponentGlobal_NotifikasiPeringatan,
} from "@/app_modules/_global/notif_global"; } from "@/app_modules/_global/notif_global";
import { gmailRegex } from "@/app_modules/katalog/component/regular_expressions";
import { Button } from "@mantine/core"; import { Button } from "@mantine/core";
import _ from "lodash"; import _ from "lodash";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useState } from "react"; import { useState } from "react";
import funCreateNewProfile from "../../fun/fun_create_profile"; import funCreateNewProfile from "../../fun/fun_create_profile";
import { MODEL_PROFILE } from "../../model/interface"; import { MODEL_PROFILE } from "../../model/interface";
import { validRegex } from "@/app_modules/katalog/component";
import { envs } from "@/lib/envs";
import { TokenProvider, TokenStorage } from "@/app/lib/token";
export function Profile_ComponentCreateNewProfile({ export function Profile_ComponentCreateNewProfile({
value, value,
@@ -40,7 +38,8 @@ export function Profile_ComponentCreateNewProfile({
}; };
if (_.values(newData).includes("")) if (_.values(newData).includes(""))
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data"); return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
if (!newData.email.match(validRegex)) return null; if (!newData.email.match(gmailRegex))
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
if (filePP == null) if (filePP == null)
return ComponentGlobal_NotifikasiPeringatan("Lengkapi foto profile"); return ComponentGlobal_NotifikasiPeringatan("Lengkapi foto profile");

View File

@@ -6,6 +6,8 @@ import {
ComponentGlobal_BoxUploadImage, ComponentGlobal_BoxUploadImage,
ComponentGlobal_ErrorInput, ComponentGlobal_ErrorInput,
} from "@/app_modules/_global/component"; } from "@/app_modules/_global/component";
import { MAX_SIZE } from "@/app_modules/_global/lib";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
import { import {
AspectRatio, AspectRatio,
Avatar, Avatar,
@@ -22,10 +24,8 @@ import {
} from "@mantine/core"; } from "@mantine/core";
import { IconAt, IconCamera, IconUpload } from "@tabler/icons-react"; import { IconAt, IconCamera, IconUpload } from "@tabler/icons-react";
import { useState } from "react"; import { useState } from "react";
import { validRegex } from "../../component";
import { Profile_ComponentCreateNewProfile } from "../_component";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
import { gmailRegex } from "../../component/regular_expressions"; import { gmailRegex } from "../../component/regular_expressions";
import { Profile_ComponentCreateNewProfile } from "../_component";
export default function CreateProfile() { export default function CreateProfile() {
const [filePP, setFilePP] = useState<File | null>(null); const [filePP, setFilePP] = useState<File | null>(null);
@@ -40,9 +40,6 @@ export default function CreateProfile() {
jenisKelamin: "", jenisKelamin: "",
}); });
// Maksimal ukuran file dalam byte (2 MB)
const MAX_SIZE = 2 * 1024 * 1024; // 2 MB
return ( return (
<> <>
<Stack px={"sm"} spacing={40}> <Stack px={"sm"} spacing={40}>

View File

@@ -4,14 +4,14 @@ import { Button, Loader, Select, Stack, TextInput } from "@mantine/core";
import _ from "lodash"; import _ from "lodash";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useState } from "react"; import { useState } from "react";
import { MainColor } from "@/app_modules/_global/color/color_pallet"; import { MainColor } from "@/app_modules/_global/color/color_pallet";
import ComponentGlobal_ErrorInput from "@/app_modules/_global/component/error_input"; import ComponentGlobal_ErrorInput from "@/app_modules/_global/component/error_input";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import { validRegex } from "../../component/regular_expressions"; import { gmailRegex, validRegex } from "../../component/regular_expressions";
import { Profile_funEditById } from "../fun/update/fun_edit_profile_by_id"; import { Profile_funEditById } from "../fun/update/fun_edit_profile_by_id";
import { MODEL_PROFILE } from "../model/interface"; import { MODEL_PROFILE } from "../model/interface";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
export default function EditProfile({ data }: { data: MODEL_PROFILE }) { export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
const router = useRouter(); const router = useRouter();
@@ -24,8 +24,10 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
const body = dataProfile; const body = dataProfile;
// console.log(body) // console.log(body)
if (_.values(body).includes("")) return null; if (_.values(body).includes(""))
if (!body.email.match(validRegex)) return null; return ComponentGlobal_NotifikasiPeringatan("Lengkapi data");
if (!body.email.match(gmailRegex))
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
await Profile_funEditById(body).then((res) => { await Profile_funEditById(body).then((res) => {
if (res.status === 200) { if (res.status === 200) {
@@ -126,7 +128,7 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
dataProfile?.email === "" ? ( dataProfile?.email === "" ? (
<ComponentGlobal_ErrorInput text="Masukan email " /> <ComponentGlobal_ErrorInput text="Masukan email " />
) : dataProfile?.email?.length > 0 && ) : dataProfile?.email?.length > 0 &&
!dataProfile?.email.match(validRegex) ? ( !dataProfile?.email.match(gmailRegex) ? (
<ComponentGlobal_ErrorInput text="Invalid email" /> <ComponentGlobal_ErrorInput text="Invalid email" />
) : ( ) : (
"" ""

View File

@@ -30,7 +30,10 @@ export default function Profile_UpdateFotoBackground({
src={ src={
image image
? image ? image
: APIs.GET({ fileId: profile.imageBackgroundId as any }) : APIs.GET({
fileId: profile.imageBackgroundId as any,
size: "400",
})
} }
/> />
</AspectRatio> </AspectRatio>

View File

@@ -27,7 +27,11 @@ export default function UploadFotoProfile({
<Image <Image
style={{ maxHeight: 250 }} style={{ maxHeight: 250 }}
alt="Avatar" alt="Avatar"
src={image ? image : APIs.GET({ fileId: profile.imageId as any })} src={
image
? image
: APIs.GET({ fileId: profile.imageId as any, size: "400" })
}
/> />
</AspectRatio> </AspectRatio>
</ComponentGlobal_BoxUploadImage> </ComponentGlobal_BoxUploadImage>