-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathModalConfirmReset.tsx
81 lines (70 loc) · 2.84 KB
/
ModalConfirmReset.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React, { useCallback, useState } from 'react'
import { Modal, ModalClose, Button, Input, Checkbox } from '@janhq/joi'
import { atom, useAtom, useAtomValue } from 'jotai'
import useFactoryReset from '@/hooks/useFactoryReset'
import { defaultJanDataFolderAtom } from '@/helpers/atoms/App.atom'
export const modalValidationAtom = atom(false)
const ModalConfirmReset = () => {
const [modalValidation, setModalValidation] = useAtom(modalValidationAtom)
const defaultJanDataFolder = useAtomValue(defaultJanDataFolderAtom)
const { resetAll } = useFactoryReset()
const [inputValue, setInputValue] = useState('')
const [currentDirectoryChecked, setCurrentDirectoryChecked] = useState(true)
const onFactoryResetClick = useCallback(() => {
setModalValidation(false)
resetAll(currentDirectoryChecked)
}, [currentDirectoryChecked, resetAll, setModalValidation])
return (
<Modal
open={modalValidation}
onOpenChange={() => setModalValidation(false)}
title="Are you sure you want to reset to default settings?"
content={
<div>
<p className="text-[hsla(var(--text-secondary))]">
Restore appplication to its initial state, erasing all models and
chat history. This action is irreversible and recommended only if
the application is corrupted.
</p>
<div className="my-4">
<p className="text-[hsla(var(--text-secondary)] mb-2 mt-1">{`To confirm, please enter the word "RESET" below:`}</p>
<Input
placeholder='Enter "RESET"'
onChange={(e) => setInputValue(e.target.value)}
/>
</div>
<div className="flex flex-shrink-0 items-start space-x-1">
<Checkbox
id="currentDirectory"
checked={currentDirectoryChecked}
onChange={(e) => setCurrentDirectoryChecked(e.target.checked)}
label="Keep the current app data location"
helperDescription={
<p className="mt-1 leading-relaxed">
Otherwise it will reset back to its original location at:{' '}
<span className="font-medium">{defaultJanDataFolder}</span>
</p>
}
/>
</div>
<div className="mt-4 flex justify-end gap-x-2">
<ModalClose asChild onClick={() => setModalValidation(false)}>
<Button theme="ghost">Cancel</Button>
</ModalClose>
<ModalClose asChild>
<Button
autoFocus
theme="destructive"
disabled={inputValue !== 'RESET'}
onClick={onFactoryResetClick}
>
Reset Now
</Button>
</ModalClose>
</div>
</div>
}
/>
)
}
export default ModalConfirmReset