Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create a account-archived page on web for archived users to export data #4355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions packages/web/components/templates/ExportDataForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useState } from 'react'
import { showErrorToast, showSuccessToast } from '../../lib/toastHelpers'
import { Button } from '../elements/Button'

export function ExportDataButton(): JSX.Element {
const [disabledState, setDisabledState] = useState<boolean>(false)

const handleExportClick = async () => {
setDisabledState(true)

try {
// Make a GET request to the /export endpoint
const response = await fetch('/api/export', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if they click this multiple times?

Copy link
Contributor Author

@sywhb sywhb Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two cases:

  1. If the export task is running, clicking this multiple times won't create multiple tasks and just return 200. Probably we should return 202 instead
  2. If the export tasks is failed/completed, clicking this multiple times will firstly check if the user has exceed the export quota(3 times in a day)
    2a. if not exceed, create a new export task
    2b. if exceed, failed and return 400

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

Is there any way in API to get the status of the export?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can reuse the same export API by providing different status code like 200 or 204. Alternatively there is a /task/{{id}} API which could be used to query the status of a task

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think probably I will just reuse the /export API and use the status code and state in the response

method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})

if (!response.ok) {
throw new Error('Failed to fetch export data')
}
} catch (error) {
console.error('Error exporting data:', error)
showErrorToast('Failed to export data')

setDisabledState(false)
return
}

showSuccessToast(
'Started exporting data. You will receive an email shortly.'
)
}

return (
<Button
type="submit"
style={disabledState ? 'ctaGray' : 'ctaOmnivoreYellow'}
css={{
padding: '10px 50px',
}}
disabled={disabledState}
onClick={() => {
handleExportClick()
}}
>
Export My Data
</Button>
)
}
16 changes: 16 additions & 0 deletions packages/web/pages/account-archived.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { VStack } from '../components/elements/LayoutPrimitives'
import { ExportDataButton } from '../components/templates/ExportDataForm'

export default function AccountArchivedPage(): JSX.Element {
return (
<VStack alignment="center" distribution="center">
<h1>Your account has been archived</h1>
<p>
Your account has been archived. If you would like to reactivate your
account, please contact support.
</p>

<ExportDataButton />
</VStack>
)
}
Loading