@samitouri / QOSami-HFS / commits / 9f3744ab

admin: disable save buttons when nothing has changed

Massimo Melina committed Feb 21, 2024 at 11:53 UTC 9f3744ab36fe46a842983674163ed62295368d8b
1 file changed +6 -6
admin/src/mui.ts
+6 -6
@@ -104,8 +104,8 @@ export function reloadBtn(onClick: any, props?: any) {
104 return h(IconBtn, { icon: Refresh, title: "Reload", onClick, ...props })
105 }
106
107 -export function modifiedProps(modified: boolean) {
108 - return modified ? { sx: { outline: '2px solid' } } : undefined
107 +export function modifiedProps(modified: boolean | undefined) {
108 + return modified === false ? { disabled: true } : undefined
109 }
110
111 function useRefPass<T=unknown>(forwarded: ForwardedRef<any>) {
@@ -141,13 +141,13 @@ export const IconBtn = forwardRef(({ title, icon, onClick, disabled, progress, l
141 title = disabled
142 if (link)
143 onClick = () => window.open(link)
144 - disabled = Boolean(loading || progress || disabled)
144 + disabled = loading || Boolean(progress) || disabled === undefined ? undefined : Boolean(disabled)
145 const ref = useRefPass<HTMLButtonElement>(forwarded)
146 let ret: ReturnType<FC> = h(IconButton, {
147 ref,
148 - disabled,
149 - ...rest,
150 - sx: { height: 'fit-content', ...modifiedProps(modified || false)?.sx, ...sx },
148 + ..._.merge(modifiedProps(modified),
149 + { disabled, sx: { height: 'fit-content', ...sx } },
150 + rest),
151 async onClick(...args) {
152 if (confirm && !await confirmDialog(confirm)) return
153 const ret = onClick?.apply(this,args)