[FEAT]: add disabled button feature
This commit is contained in:
parent
8b0687d945
commit
d9bfa52188
@ -4,12 +4,14 @@ interface IPrimaryButtonProps {
|
|||||||
title: string;
|
title: string;
|
||||||
onClick: (e: React.MouseEvent) => void;
|
onClick: (e: React.MouseEvent) => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
isDisabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PrimaryButton(props: IPrimaryButtonProps) {
|
export default function PrimaryButton(props: IPrimaryButtonProps) {
|
||||||
const { onClick, title, className } = props;
|
const { onClick, title, className, isDisabled = false } = props;
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
|
disabled={isDisabled}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
className={`py-1 px-5 transition-all hover:bg-primary-300 bg-primary-main rounded-lg text-white text-center ${className}`}
|
className={`py-1 px-5 transition-all hover:bg-primary-300 bg-primary-main rounded-lg text-white text-center ${className}`}
|
||||||
>
|
>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { HTTPPovider } from '~/driven/boundaries/http-boundary/httpBoundary';
|
import { HTTPPovider } from '~/driven/boundaries/http-boundary/httpBoundary';
|
||||||
import { HttpOptionsType } from '~/driven/boundaries/http-boundary/protocols';
|
import { HttpOptionsType } from '~/driven/boundaries/http-boundary/protocols';
|
||||||
import Notification from '~/driven/utils/components/Notification/Notification';
|
import Notification from '~/driven/utils/components/Notification/Notification';
|
||||||
@ -16,7 +16,7 @@ export default function index() {
|
|||||||
const [selectedPlaceRowId, setSelectedPlaceRowId] = useState<string>('');
|
const [selectedPlaceRowId, setSelectedPlaceRowId] = useState<string>('');
|
||||||
const { accessTokenUpdateHandler, notLoginAuth, userData } = useGetNavigatorAndTokenUpdater();
|
const { accessTokenUpdateHandler, notLoginAuth, userData } = useGetNavigatorAndTokenUpdater();
|
||||||
const [error, setError] = useState<{ message: string; type: 'error' | 'success' }>({ message: '', type: 'error' });
|
const [error, setError] = useState<{ message: string; type: 'error' | 'success' }>({ message: '', type: 'error' });
|
||||||
|
const [isSubmitDisabled, setIsSubmitDisabled] = useState(true);
|
||||||
const onSubmitMember = async (e: React.FormEvent) => {
|
const onSubmitMember = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
@ -51,6 +51,12 @@ export default function index() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedUserRowId && selectedPlaceRowId) setIsSubmitDisabled(false);
|
||||||
|
else setIsSubmitDisabled(true);
|
||||||
|
}, [selectedUserRowId, selectedPlaceRowId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{Boolean(error.message) && (
|
{Boolean(error.message) && (
|
||||||
@ -63,7 +69,12 @@ export default function index() {
|
|||||||
<PageTitle className='px-4 py-5' title={staticMessages.global.users} />
|
<PageTitle className='px-4 py-5' title={staticMessages.global.users} />
|
||||||
<div className='container mx-auto px-4'>
|
<div className='container mx-auto px-4'>
|
||||||
<form onSubmit={onSubmitMember} className='w-full flex flex-row-reverse items-center py-2 sticky top-0'>
|
<form onSubmit={onSubmitMember} className='w-full flex flex-row-reverse items-center py-2 sticky top-0'>
|
||||||
<PrimaryButton className='text-sm' title={staticMessages.global.submit} onClick={() => null} />
|
<PrimaryButton
|
||||||
|
isDisabled={isSubmitDisabled}
|
||||||
|
className='text-sm disabled:opacity-25'
|
||||||
|
title={staticMessages.global.submit}
|
||||||
|
onClick={() => null}
|
||||||
|
/>
|
||||||
</form>
|
</form>
|
||||||
<div className='md:grid-cols-2 gap-x-4 grid grid-cols-1 mx-auto'>
|
<div className='md:grid-cols-2 gap-x-4 grid grid-cols-1 mx-auto'>
|
||||||
<UsersList selectedRowId={selectedUserRowId} setSelectedRowId={setSelectedUserRowId} />
|
<UsersList selectedRowId={selectedUserRowId} setSelectedRowId={setSelectedUserRowId} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user