From 8ef550b3ec5049d8c26e8c87c4515cfd017c412b Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Thu, 5 Sep 2024 14:13:10 +0700 Subject: [PATCH 1/8] add loading and disabled state in button component --- hosting/src/app/(protected)/settings/page.tsx | 5 +- hosting/src/components/Button.tsx | 52 ++++++++++++++++--- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/hosting/src/app/(protected)/settings/page.tsx b/hosting/src/app/(protected)/settings/page.tsx index b65074ad..984d1ac4 100644 --- a/hosting/src/app/(protected)/settings/page.tsx +++ b/hosting/src/app/(protected)/settings/page.tsx @@ -21,6 +21,7 @@ export default function Settings() { const {isLoading: uploadLoading, error: storageError, upload, getFile} = useFirebaseStorage(); const [notification, setNotification] = useState(null); + const [readonlyMode, setReadonlyMode] = useState(true); const [showDropzone, setShowDropzone] = useState(false); const [showCropImage, setShowCropImage] = useState(false); const [pathUpload, setPathUpload] = useState(); @@ -58,6 +59,7 @@ export default function Settings() { * @return {Promise} */ async function resetChanges(): Promise { + setReadonlyMode(true); setFileUploadContentType(undefined); resetCropImage(); @@ -264,7 +266,8 @@ export default function Settings() { Cancel ); } From 70d774a8562773ae47a73adf2ef653bbf0514f1e Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Thu, 5 Sep 2024 14:20:34 +0700 Subject: [PATCH 2/8] add missing type button --- hosting/src/components/Button.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hosting/src/components/Button.tsx b/hosting/src/components/Button.tsx index de439f69..3f65da8c 100644 --- a/hosting/src/components/Button.tsx +++ b/hosting/src/components/Button.tsx @@ -5,13 +5,14 @@ interface ButtonProps { onClick: () => Promise | void; style?: "normal" | "rounded" | "outline" | "outline-rounded" | "icon" | "icon-rounded"; color?: "primary" | "meta-3" | "black"; + type?: "button" | "reset" | "submit"; loading?: boolean; disabled?: boolean; children?: React.ReactNode; } export function Button(props: ButtonProps) { - const {title, onClick, style = "rounded", color = "primary", children, loading, disabled} = props; + const {title, onClick, style = "rounded", color = "primary", children, loading, disabled, type} = props; const [isLoading, setIsLoading] = useState(loading ?? false); const [isDisabled, setIsDisabled] = useState(disabled ?? false); @@ -84,11 +85,11 @@ export function Button(props: ButtonProps) { } return ( - + + + loading={isLoading} + disabled={isDisabled} + style="outline-rounded" + color="black" + /> {/* End button to close the crop image modal */} {/* Start button to save changes to the profile picture after cropping */} - + /> {/* End button to save changes to the profile picture after cropping */} ); @@ -220,18 +230,26 @@ export default function Settings() {
Edit your photo - - + /> + +
@@ -261,11 +279,12 @@ export default function Settings() {
@@ -273,22 +292,30 @@ export default function Settings() {
- - - + {readonlyMode && ( +
diff --git a/hosting/src/components/Button.tsx b/hosting/src/components/Button.tsx index c3bc0c98..af9004cc 100644 --- a/hosting/src/components/Button.tsx +++ b/hosting/src/components/Button.tsx @@ -4,9 +4,10 @@ import React, {useEffect, useState} from "react"; interface ButtonProps { title: string; onClick?: () => Promise | void; - style?: "normal" | "rounded" | "outline" | "outline-rounded" | "icon" | "icon-rounded"; + style?: "normal" | "plain-text" | "rounded" | "outline" | "outline-rounded" | "icon" | "icon-rounded"; color?: "primary" | "meta-3" | "black"; type?: "button" | "reset" | "submit"; + className?: string[]; loading?: boolean; disabled?: boolean; children?: React.ReactNode; @@ -22,6 +23,7 @@ export function Button(props: ButtonProps) { loading = false, disabled = false, type, + className = [], } = props; const [isLoading, setIsLoading] = useState(loading); @@ -77,6 +79,10 @@ export function Button(props: ButtonProps) { switch (style) { case "normal": break; + case "plain-text": + styles = styles.filter((style) => style !== "text-white"); + styles.push("!bg-transparent", `hover:text-${color}`); + break; case "rounded": styles.push("rounded-md"); break; @@ -97,6 +103,8 @@ export function Button(props: ButtonProps) { break; } + styles = styles.concat(styles, ...className); + return (