@ -10,8 +10,9 @@ import {
createMemo ,
onMount ,
onCleanup ,
mergeProps ,
} from "solid-js" ;
import { createStore , reconcile, unwrap } from "solid-js/store" ;
import { createStore , produce, reconcile, unwrap } from "solid-js/store" ;
import { format , fromUnixTime , getUnixTime } from "date-fns" ;
import z from "myzod" ;
import Big from "big.js" ;
@ -51,7 +52,11 @@ import {
storeSchema ,
UiStoreContext ,
} from "~/stores" ;
import { AddressData , isStructuredAddress } from "../Address" ;
import {
applyAddress ,
isStructuredAddress ,
PostalAddressData ,
} from "../Address" ;
import PositionsIcon from "~icons/carbon/show-data-cards" ;
import YouIcon from "~icons/carbon/face-wink" ;
import DesignIcon from "~icons/carbon/paint-brush" ;
@ -110,11 +115,13 @@ const SettingsOverlay: Component = () => {
const [ CustomerValidationContext , customerDataForm ] = createValidation ( ) ;
const AddressInputs : Component < {
postal? : boolean ;
namePrefix? : string ;
nameRequired? : boolean ;
setter : ( name : string , value : any ) = > void ;
address : ( ) = > AddressData ;
} > = ( props ) = > {
address : ( ) = > PostalAddressData ;
} > = ( p ) = > {
const props = mergeProps ( { postal : false } , p ) ;
const isStructured = createMemo ( ( ) = > isStructuredAddress ( props . address ( ) ) ) ;
const withPrefix = ( name : string ) = >
createMemo (
@ -123,7 +130,11 @@ const SettingsOverlay: Component = () => {
return (
< >
< div class = "col-span-2" >
< div
classList = { {
"col-span-2" : ! props . postal ,
} }
>
< TextInput
name = { withPrefix ( "name" ) }
label = "Name"
@ -134,6 +145,15 @@ const SettingsOverlay: Component = () => {
/ >
< / div >
< Show when = { props . nameRequired || props . address ( ) . name } >
< Show when = { props . postal } >
< TextInput
name = { withPrefix ( "name2" ) }
label = "Name 2"
maxLength = { 70 }
value = { props . address ( ) . name2 }
onInput = { ( evt ) = > props . setter ( "name2" , evt . currentTarget . value ) }
/ >
< / Show >
< TextInput
name = { withPrefix ( "line1" ) }
label = { isStructured ( ) ? "Strasse" : "Linie 1" }
@ -581,11 +601,29 @@ const SettingsOverlay: Component = () => {
< AddressInputs
namePrefix = "customAddress"
nameRequired = { true }
postal
setter = { ( name , value ) = > {
setLocalState ( "customAddress" , name as any , value ) ;
} }
address = { ( ) = > localState . customAddress }
/ >
< div class = "col-span-2" >
< button
class = "btn btn-xs btn-accent btn-block"
onClick = { ( ) = > {
setLocalState (
produce ( ( s ) = > {
applyAddress (
s . customAddress ,
localState . creditor
) ;
} )
) ;
} }
>
Von Bank Verbindung ü bernehmen
< / button >
< / div >
< / AccordionItemGrid >
< / Show >
< / div >
@ -705,9 +743,28 @@ const SettingsOverlay: Component = () => {
< Show when = { state . useCustomerAlternativeAddress } >
< AccordionItemGrid >
< AddressInputs
nameRequired
postal
setter = { createCustomerAddressSetter ( true ) }
address = { ( ) = > state . customer . alternativeAddress }
/ >
< div class = "col-span-2" >
< button
class = "btn btn-xs btn-accent btn-block"
onClick = { ( ) = > {
setState (
produce ( ( s ) = > {
applyAddress (
s . customer . alternativeAddress ,
state . customer . debtorAddress
) ;
} )
) ;
} }
>
Von Bank Verbindung ü bernehmen
< / button >
< / div >
< / AccordionItemGrid >
< / Show >
< / div >