|
| 1 | +import type { Customer } from '@/api/dataclasses/customer' |
| 2 | +import type { Translation } from '@helpwave/common/hooks/useTranslation' |
| 3 | +import { useTranslation } from '@helpwave/common/hooks/useTranslation' |
| 4 | +import { tw, tx } from '@twind/core' |
| 5 | +import { Input } from '@helpwave/common/components/user-input/Input' |
| 6 | +import { Button } from '@helpwave/common/components/Button' |
| 7 | + |
| 8 | +type ContactInformationTranslation = { |
| 9 | + contactInfo: string, |
| 10 | + additionalInformation: string, |
| 11 | + name: string, |
| 12 | + websiteUrl: string, |
| 13 | + email: string, |
| 14 | + phone: string, |
| 15 | + address: string, |
| 16 | + street: string, |
| 17 | + houseNumber: string, |
| 18 | + houseNumberAdditional: string, |
| 19 | + postalCode: string, |
| 20 | + city: string, |
| 21 | + country: string, |
| 22 | + save: string, |
| 23 | +} |
| 24 | + |
| 25 | +const defaultContactInformationTranslation: Translation<ContactInformationTranslation> = { |
| 26 | + en: { |
| 27 | + contactInfo: 'Contact Information', |
| 28 | + additionalInformation: 'Additional Information', |
| 29 | + name: 'Name', |
| 30 | + websiteUrl: 'Website URL', |
| 31 | + email: 'Email', |
| 32 | + phone: 'Phonenumber', |
| 33 | + address: 'Address', |
| 34 | + street: 'Street', |
| 35 | + houseNumber: 'Housenumber', |
| 36 | + houseNumberAdditional: 'Addition', |
| 37 | + postalCode: 'Postal code', |
| 38 | + city: 'City', |
| 39 | + country: 'Country', |
| 40 | + save: 'Save' |
| 41 | + }, |
| 42 | + de: { |
| 43 | + contactInfo: 'Kontakt Informationen', |
| 44 | + additionalInformation: 'Zusätzliche Informationen', |
| 45 | + name: 'Name', |
| 46 | + websiteUrl: 'Website URL', |
| 47 | + email: 'Email', |
| 48 | + phone: 'Telefonnummer', |
| 49 | + address: 'Adresse', |
| 50 | + street: 'Straße', |
| 51 | + houseNumber: 'Hausnummer', |
| 52 | + houseNumberAdditional: 'Zusatz', |
| 53 | + postalCode: 'Postleitzahl', |
| 54 | + city: 'Stadt', |
| 55 | + country: 'Land', |
| 56 | + save: 'Speichern' |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +type ContactInformationFormProps = { |
| 61 | + value: Customer, |
| 62 | + onChange: (customer: Customer) => void, |
| 63 | + onSubmit: (customer: Customer) => void, |
| 64 | + className?: string, |
| 65 | +} |
| 66 | + |
| 67 | +export const ContactInformationForm = ({ value, onChange, onSubmit, className }: ContactInformationFormProps) => { |
| 68 | + const translation = useTranslation(defaultContactInformationTranslation) |
| 69 | + return ( |
| 70 | + <form className={tx('@(flex flex-col gap-y-1 max-w-[700px])', className)}> |
| 71 | + <h3 className={tw('font-space font-bold text-2xl')}>{translation.contactInfo}</h3> |
| 72 | + <Input |
| 73 | + value={value.name} |
| 74 | + onChange={name => onChange({ ...value, name })} |
| 75 | + label={{ name: translation.name }} |
| 76 | + /> |
| 77 | + <Input |
| 78 | + value={value.email} |
| 79 | + onChange={email => onChange({ ...value, email })} |
| 80 | + label={{ name: translation.email }} |
| 81 | + /> |
| 82 | + <Input |
| 83 | + value={value.phoneNumber ?? ''} |
| 84 | + onChange={phoneNumber => onChange({ ...value, phoneNumber })} |
| 85 | + label={{ name: translation.phone }} |
| 86 | + /> |
| 87 | + <div className={tw('flex flex-col gap-y-1')}> |
| 88 | + <h4 className={tw('font-space font-bold text-lg')}>{translation.address}</h4> |
| 89 | + <Input |
| 90 | + value={value.address.country ?? ''} |
| 91 | + onChange={country => onChange({ ...value, address: { ...value.address, country } })} |
| 92 | + label={{ name: translation.country }} |
| 93 | + /> |
| 94 | + <div className={tw('flex flex-row gap-x-1')}> |
| 95 | + <Input |
| 96 | + value={value.address.city ?? ''} |
| 97 | + onChange={city => onChange({ ...value, address: { ...value.address, city } })} |
| 98 | + label={{ name: translation.city }} |
| 99 | + /> |
| 100 | + <Input |
| 101 | + value={value.address.postalCode ?? ''} |
| 102 | + onChange={postalCode => onChange({ |
| 103 | + ...value, |
| 104 | + address: { ...value.address, postalCode } |
| 105 | + })} |
| 106 | + label={{ name: translation.postalCode }} |
| 107 | + containerClassName={tw('max-w-[180px]')} |
| 108 | + /> |
| 109 | + </div> |
| 110 | + <div className={tw('flex flex-row gap-x-1')}> |
| 111 | + <Input |
| 112 | + value={value.address.street ?? ''} |
| 113 | + onChange={street => onChange({ |
| 114 | + ...value, |
| 115 | + address: { ...value.address, street } |
| 116 | + })} |
| 117 | + label={{ name: translation.street }} |
| 118 | + /> |
| 119 | + <Input |
| 120 | + value={value.address.houseNumber ?? ''} |
| 121 | + onChange={houseNumber => onChange({ |
| 122 | + ...value, |
| 123 | + address: { ...value.address, houseNumber } |
| 124 | + })} |
| 125 | + label={{ name: translation.houseNumber }} |
| 126 | + containerClassName={tw('max-w-[180px]')} |
| 127 | + /> |
| 128 | + <Input |
| 129 | + value={value.address.houseNumberAdditional ?? ''} |
| 130 | + onChange={houseNumberAdditional => onChange({ |
| 131 | + ...value, |
| 132 | + address: { ...value.address, houseNumberAdditional } |
| 133 | + })} |
| 134 | + label={{ name: translation.houseNumberAdditional }} |
| 135 | + containerClassName={tw('max-w-[180px]')} |
| 136 | + /> |
| 137 | + </div> |
| 138 | + <div className={tw('flex flex-col gap-y-1')}> |
| 139 | + <h4 className={tw('font-space font-bold text-lg')}>{translation.additionalInformation}</h4> |
| 140 | + <Input |
| 141 | + value={value.websiteURL ?? ''} |
| 142 | + onChange={websiteURL => onChange({ ...value, websiteURL })} |
| 143 | + label={{ name: translation.websiteUrl }} |
| 144 | + /> |
| 145 | + </div> |
| 146 | + </div> |
| 147 | + |
| 148 | + <div className={tw('flex flex-row justify-end')}> |
| 149 | + <Button onClick={() => onSubmit(value)}>{translation.save}</Button> |
| 150 | + </div> |
| 151 | + </form> |
| 152 | + ) |
| 153 | +} |
0 commit comments