1
0
Fork 0
mirror of synced 2024-07-19 13:15:49 +12:00

Add validation

This commit is contained in:
Adria Navarro 2023-06-13 11:57:56 +01:00
parent e0664222fe
commit 32dde23728

View file

@ -6,16 +6,28 @@
InlineAlert, InlineAlert,
Input, Input,
} from "@budibase/bbui" } from "@budibase/bbui"
import { createValidationStore } from "helpers/validation/yup"
export let app export let app
export let published export let published
let includeInternalTablesRows = true let includeInternalTablesRows = true
let encypt = true let encypt = true
let password let password
let passwordError const validation = createValidationStore()
validation.addValidatorType("password", "password", "true")
function validate() {
return validation.check({ password })
}
$: {
if ($validation.errors.length) {
validate()
}
}
const Step = { CONFIG: "config", SET_PASSWORD: "set_password" } const Step = { CONFIG: "config", SET_PASSWORD: "set_password" }
let currentStep = Step.CONFIG let currentStep = Step.SET_PASSWORD
$: exportButtonText = published ? "Export published" : "Export latest" $: exportButtonText = published ? "Export published" : "Export latest"
$: stepConfig = { $: stepConfig = {
@ -34,9 +46,9 @@
[Step.SET_PASSWORD]: { [Step.SET_PASSWORD]: {
title: "Add password to encrypt your export", title: "Add password to encrypt your export",
confirmText: exportButtonText, confirmText: exportButtonText,
onConfirm: () => { onConfirm: async () => {
if (!password) { await validate()
passwordError = "Password is required" if (!$validation.valid) {
return false return false
} }
exportApp() exportApp()
@ -57,25 +69,26 @@
onConfirm={stepConfig[currentStep].onConfirm} onConfirm={stepConfig[currentStep].onConfirm}
> >
{#if currentStep === Step.CONFIG} {#if currentStep === Step.CONFIG}
<Body> <Body>
<Toggle <Toggle
text="Export rows from internal tables" text="Export rows from internal tables"
bind:value={includeInternalTablesRows} bind:value={includeInternalTablesRows}
/> />
<Toggle text="Encrypt my export" bind:value={encypt} /> <Toggle text="Encrypt my export" bind:value={encypt} />
</Body> </Body>
{#if !encypt} {#if !encypt}
<InlineAlert <InlineAlert
header="Do not share your budibase application exports publicly as they may contain sensitive information such as database credentials or secret keys." header="Do not share your budibase application exports publicly as they may contain sensitive information such as database credentials or secret keys."
/> />
{/if} {/if}
{/if} {/if}
{#if currentStep === Step.SET_PASSWORD} {#if currentStep === Step.SET_PASSWORD}
<Input <Input
type="password"
label="Password" label="Password"
placeholder="Type here..." placeholder="Type here..."
bind:value={password} bind:value={password}
error={passwordError} error={$validation.errors.password}
/> />
{/if} {/if}
</ModalContent> </ModalContent>