forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request umami-software#762 from mikecao/dev
v1.22.0
- Loading branch information
Showing
16 changed files
with
915 additions
and
724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React, { useState } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Formik, Form, Field } from 'formik'; | ||
import Button from 'components/common/Button'; | ||
import FormLayout, { | ||
FormButtons, | ||
FormError, | ||
FormMessage, | ||
FormRow, | ||
} from 'components/layout/FormLayout'; | ||
import usePost from 'hooks/usePost'; | ||
|
||
const CONFIRMATION_WORD = 'RESET'; | ||
|
||
const validate = ({ confirmation }) => { | ||
const errors = {}; | ||
|
||
if (confirmation !== CONFIRMATION_WORD) { | ||
errors.confirmation = !confirmation ? ( | ||
<FormattedMessage id="label.required" defaultMessage="Required" /> | ||
) : ( | ||
<FormattedMessage id="label.invalid" defaultMessage="Invalid" /> | ||
); | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
export default function ResetForm({ values, onSave, onClose }) { | ||
const post = usePost(); | ||
const [message, setMessage] = useState(); | ||
|
||
const handleSubmit = async ({ type, id }) => { | ||
const { ok, data } = await post(`/api/${type}/${id}/reset`); | ||
|
||
if (ok) { | ||
onSave(); | ||
} else { | ||
setMessage( | ||
data || <FormattedMessage id="message.failure" defaultMessage="Something went wrong." />, | ||
); | ||
} | ||
}; | ||
|
||
return ( | ||
<FormLayout> | ||
<Formik | ||
initialValues={{ confirmation: '', ...values }} | ||
validate={validate} | ||
onSubmit={handleSubmit} | ||
> | ||
{props => ( | ||
<Form> | ||
<div> | ||
<FormattedMessage | ||
id="message.confirm-reset" | ||
defaultMessage="Are your sure you want to reset {target}'s statistics?" | ||
values={{ target: <b>{values.name}</b> }} | ||
/> | ||
</div> | ||
<div> | ||
<FormattedMessage | ||
id="message.reset-warning" | ||
defaultMessage="All statistics for this website will be deleted, but your tracking code will remain intact." | ||
/> | ||
</div> | ||
<p> | ||
<FormattedMessage | ||
id="message.type-reset" | ||
defaultMessage="Type {reset} in the box below to confirm." | ||
values={{ reset: <b>{CONFIRMATION_WORD}</b> }} | ||
/> | ||
</p> | ||
<FormRow> | ||
<div> | ||
<Field name="confirmation" type="text" /> | ||
<FormError name="confirmation" /> | ||
</div> | ||
</FormRow> | ||
<FormButtons> | ||
<Button | ||
type="submit" | ||
variant="danger" | ||
disabled={props.values.confirmation !== CONFIRMATION_WORD} | ||
> | ||
<FormattedMessage id="label.reset" defaultMessage="Reset" /> | ||
</Button> | ||
<Button onClick={onClose}> | ||
<FormattedMessage id="label.cancel" defaultMessage="Cancel" /> | ||
</Button> | ||
</FormButtons> | ||
<FormMessage>{message}</FormMessage> | ||
</Form> | ||
)} | ||
</Formik> | ||
</FormLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.