2023-04-28 21:23:06 +02:00
|
|
|
// Hooks
|
|
|
|
import { useContext } from 'react'
|
2023-02-12 18:35:54 +01:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-04-28 21:23:06 +02:00
|
|
|
// Context
|
2023-09-04 08:40:05 +02:00
|
|
|
import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs'
|
2023-04-28 21:23:06 +02:00
|
|
|
// Components
|
|
|
|
import { Spinner } from 'shared/components/spinner.mjs'
|
2023-02-12 18:35:54 +01:00
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
export const SaveSettingsButton = ({ btnProps = {}, welcome = false, label = false }) => {
|
2023-09-04 08:40:05 +02:00
|
|
|
const { loading } = useContext(LoadingStatusContext)
|
2023-02-12 18:35:54 +01:00
|
|
|
const { t } = useTranslation(['account'])
|
|
|
|
let classes = 'btn mt-4 capitalize '
|
|
|
|
if (welcome) {
|
|
|
|
classes += 'w-64 '
|
2023-04-28 21:23:06 +02:00
|
|
|
if (loading) classes += 'btn-accent '
|
2023-02-12 18:35:54 +01:00
|
|
|
else classes += 'btn-secondary '
|
|
|
|
} else {
|
|
|
|
classes += 'w-full '
|
2023-04-28 21:23:06 +02:00
|
|
|
if (loading) classes += 'btn-accent '
|
2023-02-12 18:35:54 +01:00
|
|
|
else classes += 'btn-primary '
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<button className={classes} tabIndex="-1" role="button" {...btnProps}>
|
|
|
|
<span className="flex flex-row items-center gap-2">
|
2023-04-28 21:23:06 +02:00
|
|
|
{loading ? (
|
2023-02-12 18:35:54 +01:00
|
|
|
<>
|
|
|
|
<Spinner />
|
|
|
|
<span>{t('processing')}</span>
|
|
|
|
</>
|
2023-02-18 16:11:02 +01:00
|
|
|
) : label ? (
|
|
|
|
<span>{label}</span>
|
2023-02-12 18:35:54 +01:00
|
|
|
) : (
|
|
|
|
<span>{t('save')}</span>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|