Skip to content

Commit

Permalink
fix: prevent updating before not loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
pmh-only committed Aug 20, 2023
1 parent bc57cae commit 6844699
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/InstanceTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const InstanceTable: FC<Props> = ({ instances, isLoading }) => {
const { refresh } = useRefreshNotifier()
const [uuid, setUuid] = useState('')
const [updateModalStatus, setUpdateModal] = useState(false)
const [isUpdateLoading, setIsUpdateLoading] = useState(false)
const [event, dispatch] = useReducer(updateModalReducer, {
category: '',
name: '',
Expand Down Expand Up @@ -81,6 +82,11 @@ const InstanceTable: FC<Props> = ({ instances, isLoading }) => {
}

async function updateForm (uuid: string): Promise<void> {
if (isUpdateLoading)
return

setIsUpdateLoading(true)

await axios(`/api/instances/${uuid}`, {
method: 'GET'
}).then((res) => {
Expand All @@ -96,6 +102,8 @@ const InstanceTable: FC<Props> = ({ instances, isLoading }) => {
}).catch((err) => {
console.error(err)
})

setIsUpdateLoading(false)
}

async function inviteInstance (uuid: string): Promise<void> {
Expand Down Expand Up @@ -167,8 +175,8 @@ const InstanceTable: FC<Props> = ({ instances, isLoading }) => {
삭제
</Button>

<Button className='orangeButton ButtonList' variant="primary" onClick={() => { void updateForm(item.id) }}>
수정
<Button disabled={isUpdateLoading} className='orangeButton ButtonList' variant="primary" onClick={() => { void updateForm(item.id) }}>
{isUpdateLoading ? '...' : '수정'}
</Button>
</div>
),
Expand Down

0 comments on commit 6844699

Please sign in to comment.