Skip to content

Commit

Permalink
feat: track loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
Chisomchima committed Nov 19, 2024
1 parent 1249b5a commit 211ce07
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
2 changes: 0 additions & 2 deletions src/layout/FormFields.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ function createAvatarEditor(fieldBase, d2, valueStore) {
}

function createFieldBaseObject(fieldName, mapping, valueStore) {
console.log('Field:', fieldName, 'Mapping:', mapping)

if (!mapping) {
log.warn(`Mapping not found for field: ${fieldName}`)
return null // Skip this field
Expand Down
44 changes: 25 additions & 19 deletions src/layout/VerifyEmail.component.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { useAlert } from '@dhis2/app-runtime'
import { CircularLoader } from '@dhis2/ui'
import { getInstance as getD2 } from 'd2'
import { blue400 } from 'material-ui/styles/colors.js'
import React from 'react'
import React, { useState } from 'react'

export function VerifyEmail() {
const errorAlert = useAlert(({ message }) => message, { critical: true })
const successAlert = useAlert(({ message }) => message, { success: true })
const [isLoading, setIsLoading] = useState(false)

const handleEmailVerification = async () => {
setIsLoading(true)
try {
const d2 = await getD2()
const api = d2.Api.getApi()
api.baseUrl = 'http://localhost:8080/'

const res = await api.post('account/sendEmailVerification')
console.log('Response:', res)
await api.post('account/sendEmailVerification')
successAlert.show({
message: 'Email verification link sent successfully!',
})
Expand All @@ -24,24 +25,29 @@ export function VerifyEmail() {
message:
err.message || 'Failed to send email verification link.',
})
} finally {
setIsLoading(false)
}
}

return (
<button
type="button"
style={{
marginTop: '10px',
background: 'white',
border: '1px solid',
borderColor: blue400,
color: blue400,
padding: '10px',
cursor: 'pointer',
}}
onClick={handleEmailVerification}
>
Verify Email
</button>
<div style={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
<button
type="button"
style={{
background: 'white',
border: '1px solid',
borderColor: '#1976D2',
color: '#1976D2',
padding: '10px',
cursor: isLoading ? 'not-allowed' : 'pointer',
}}
onClick={handleEmailVerification}
disabled={isLoading}
>
Verify Email
</button>
{isLoading && <CircularLoader small />}
</div>
)
}

0 comments on commit 211ce07

Please sign in to comment.