fix: some details

This commit is contained in:
Daniel Soares committed 2021-12-15 08:11:58 -03:00
1 parent 2f4dd0097b
commit 5df44ceddc
22 files changed
+330 -118

No files matched your search

@@ -0,0 +1,62 @@
import { useRouter } from 'next/router'
import type { Dispatch, SetStateAction } from 'react'
import { useData } from '../../../hooks/useData'
import { api } from '../../../services/api'
import type { Data } from '../../../types/Data'
import { removeLocalStorageData } from '../../../utils/localStorage'
import { Button } from '../../Button'
import { ButtonsGroup, Wrapper } from './styles'
type SaveChangesAlertProps = {
hasUnsavedChanges: boolean
setHasUnsavedChanges: Dispatch<SetStateAction<boolean>>
initialData: Data
}
export function SaveChangesAlert({
hasUnsavedChanges,
setHasUnsavedChanges,
initialData
}: SaveChangesAlertProps) {
const { push } = useRouter()
const { data, setData } = useData()
const handleSave = async () => {
try {
await api.put('data', { data })
removeLocalStorageData()
setHasUnsavedChanges(false)
setData(data)
push('/')
} catch (error) {
console.error(error)
}
}
const handleCancel = () => {
setHasUnsavedChanges(false)
removeLocalStorageData()
setData(initialData)
}
return (
<Wrapper show={hasUnsavedChanges}>
You have unsaved changes.
<ButtonsGroup>
<Button
size="small"
styleSchema="square"
colorSchema="rose"
outline
onClick={() => handleCancel()}
>
Cancel
</Button>
<Button size="small" styleSchema="square" colorSchema="slate" onClick={() => handleSave()}>
Save
</Button>
</ButtonsGroup>
</Wrapper>
)
}
@@ -0,0 +1,38 @@
import { styled, theme } from '../../../styles/stitches.config'
export const Wrapper = styled('div', {
position: 'fixed',
top: 0,
left: 0,
width: '50%',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
padding: '1rem',
background: theme.colors.sky200,
color: theme.colors.slate700,
fontFamily: theme.fonts.roboto,
fontSize: '0.875rem',
lineHeight: 1,
transition: 'all 0.25s ease-in-out',
variants: {
show: {
true: {
opacity: 1
},
false: {
opacity: 0
}
}
},
defaultVariant: {
show: false
}
})
export const ButtonsGroup = styled('div', {
display: 'flex',
gap: '1rem'
})