|
1 | 1 | import clsx from 'clsx' |
2 | 2 | import type { Languages } from '@helpwave/hightide' |
3 | | -import { useTranslation, type PropsForTranslation } from '@helpwave/hightide' |
4 | | -import { Input } from '@helpwave/hightide' |
5 | | -import { validateEmail } from '@helpwave/hightide' |
6 | | -import { LoadingAndErrorComponent } from '@helpwave/hightide' |
| 3 | +import { |
| 4 | + Input, |
| 5 | + LoadingAndErrorComponent, |
| 6 | + type PropsForTranslation, |
| 7 | + useTranslation, |
| 8 | + validateEmail |
| 9 | +} from '@helpwave/hightide' |
7 | 10 | import type { OrganizationMinimalDTO } from '@helpwave/api-services/types/users/organizations' |
8 | 11 | import { emptyOrganization } from '@helpwave/api-services/types/users/organizations' |
9 | 12 |
|
@@ -91,10 +94,10 @@ export type OrganizationFormProps = { |
91 | 94 | * The state is manged by the parent |
92 | 95 | */ |
93 | 96 | export const OrganizationForm = ({ |
94 | | - overwriteTranslation, |
95 | | - organizationForm = emptyOrganizationForm, |
96 | | - onChange = () => undefined, |
97 | | -}: PropsForTranslation<OrganizationFormTranslation, OrganizationFormProps>) => { |
| 97 | + overwriteTranslation, |
| 98 | + organizationForm = emptyOrganizationForm, |
| 99 | + onChange = () => undefined, |
| 100 | + }: PropsForTranslation<OrganizationFormTranslation, OrganizationFormProps>) => { |
98 | 101 | const translation = useTranslation(defaultOrganizationFormTranslations, overwriteTranslation) |
99 | 102 |
|
100 | 103 | const minShortNameLength = 2 |
@@ -156,58 +159,87 @@ export const OrganizationForm = ({ |
156 | 159 | loadingProps={{ classname: 'border-2 border-gray-500 rounded-xl min-h-[350px]' }} |
157 | 160 | minimumLoadingDuration={200} // prevents errors flickering |
158 | 161 | > |
159 | | - <span className="textstyle-title-normal">{translation.general}</span> |
160 | | - <div className="mt-2 mb-1"> |
161 | | - <Input |
162 | | - id="shortName" |
163 | | - value={organizationForm.organization.shortName} |
164 | | - label={{ name: translation.shortName }} |
165 | | - onBlur={() => triggerOnChange({ ...organizationForm.organization }, false, { ...organizationForm.touched, shortName: true })} |
166 | | - onChange={text => triggerOnChange({ ...organizationForm.organization, shortName: text }, false, { ...organizationForm.touched })} |
167 | | - onEditCompleted={text => triggerOnChange({ ...organizationForm.organization, shortName: text }, true, { ...organizationForm.touched, shortName: true })} |
168 | | - maxLength={maxShortNameLength} |
169 | | - className={clsx(inputClasses, { [inputErrorClasses]: isDisplayingShortNameError })} |
170 | | - /> |
171 | | - {isDisplayingShortNameError && <span className="textstyle-form-error">{shortNameErrorMessage}</span>} |
172 | | - </div> |
173 | | - <span className="textstyle-form-description">{translation.shortNameDescription}</span> |
174 | | - <div className="mt-2 mb-1"> |
175 | | - <Input |
176 | | - id="longName" |
177 | | - value={organizationForm.organization.longName} |
178 | | - label={{ name: translation.longName }} |
179 | | - onBlur={() => triggerOnChange({ ...organizationForm.organization }, false, { ...organizationForm.touched, longName: true })} |
180 | | - onChange={text => triggerOnChange({ ...organizationForm.organization, longName: text }, false, { ...organizationForm.touched })} |
181 | | - onEditCompleted={text => triggerOnChange({ ...organizationForm.organization, longName: text }, true, { ...organizationForm.touched, longName: true })} |
182 | | - maxLength={maxLongNameLength} |
183 | | - className={clsx(inputClasses, { [inputErrorClasses]: isDisplayingLongNameError })} |
184 | | - /> |
185 | | - {isDisplayingLongNameError && <span className="textstyle-form-error">{longNameErrorMessage}</span>} |
186 | | - </div> |
187 | | - <span className="textstyle-form-description">{translation.longNameDescription}</span> |
188 | | - <div className="mt-2 mb-1"> |
189 | | - <div className="row items-end"> |
190 | | - <div className="flex-1 mr-2"> |
191 | | - <Input |
192 | | - id="email" |
193 | | - value={organizationForm.organization.email} |
194 | | - label={{ name: translation.contactEmail }} |
195 | | - type="email" |
196 | | - onBlur={() => triggerOnChange({ ...organizationForm.organization }, false, { ...organizationForm.touched, email: true })} |
197 | | - onChange={text => triggerOnChange({ ...organizationForm.organization, email: text }, false, { ...organizationForm.touched })} |
198 | | - onEditCompleted={text => triggerOnChange({ ...organizationForm.organization, email: text }, true, { ...organizationForm.touched, email: true })} |
199 | | - maxLength={maxMailLength} |
200 | | - className={clsx(inputClasses, { [inputErrorClasses]: isDisplayingEmailNameError })} |
201 | | - /> |
| 162 | + <div className="col gap-y-4"> |
| 163 | + <span className="textstyle-title-normal">{translation.general}</span> |
| 164 | + <div className="col gap-y-1"> |
| 165 | + <Input |
| 166 | + id="shortName" |
| 167 | + value={organizationForm.organization.shortName} |
| 168 | + label={{ name: translation.shortName }} |
| 169 | + onBlur={() => triggerOnChange({ ...organizationForm.organization }, false, { |
| 170 | + ...organizationForm.touched, |
| 171 | + shortName: true |
| 172 | + })} |
| 173 | + onChange={text => triggerOnChange({ |
| 174 | + ...organizationForm.organization, |
| 175 | + shortName: text |
| 176 | + }, false, { ...organizationForm.touched })} |
| 177 | + onEditCompleted={text => triggerOnChange({ |
| 178 | + ...organizationForm.organization, |
| 179 | + shortName: text |
| 180 | + }, true, { ...organizationForm.touched, shortName: true })} |
| 181 | + maxLength={maxShortNameLength} |
| 182 | + className={clsx(inputClasses, { [inputErrorClasses]: isDisplayingShortNameError })} |
| 183 | + /> |
| 184 | + {isDisplayingShortNameError && <span className="textstyle-form-error">{shortNameErrorMessage}</span>} |
| 185 | + <span className="textstyle-form-description">{translation.shortNameDescription}</span> |
| 186 | + </div> |
| 187 | + <div className="col gap-y-1"> |
| 188 | + <Input |
| 189 | + id="longName" |
| 190 | + value={organizationForm.organization.longName} |
| 191 | + label={{ name: translation.longName }} |
| 192 | + onBlur={() => triggerOnChange({ ...organizationForm.organization }, false, { |
| 193 | + ...organizationForm.touched, |
| 194 | + longName: true |
| 195 | + })} |
| 196 | + onChange={text => triggerOnChange({ |
| 197 | + ...organizationForm.organization, |
| 198 | + longName: text |
| 199 | + }, false, { ...organizationForm.touched })} |
| 200 | + onEditCompleted={text => triggerOnChange({ |
| 201 | + ...organizationForm.organization, |
| 202 | + longName: text |
| 203 | + }, true, { ...organizationForm.touched, longName: true })} |
| 204 | + maxLength={maxLongNameLength} |
| 205 | + className={clsx(inputClasses, { [inputErrorClasses]: isDisplayingLongNameError })} |
| 206 | + /> |
| 207 | + {isDisplayingLongNameError && <span className="textstyle-form-error">{longNameErrorMessage}</span>} |
| 208 | + <span className="textstyle-form-description">{translation.longNameDescription}</span> |
| 209 | + </div> |
| 210 | + <div className="col gap-y-1"> |
| 211 | + <div className="row items-end"> |
| 212 | + <div className="flex-1 mr-2"> |
| 213 | + <Input |
| 214 | + id="email" |
| 215 | + value={organizationForm.organization.email} |
| 216 | + label={{ name: translation.contactEmail }} |
| 217 | + type="email" |
| 218 | + onBlur={() => triggerOnChange({ ...organizationForm.organization }, false, { |
| 219 | + ...organizationForm.touched, |
| 220 | + email: true |
| 221 | + })} |
| 222 | + onChange={text => triggerOnChange({ |
| 223 | + ...organizationForm.organization, |
| 224 | + email: text |
| 225 | + }, false, { ...organizationForm.touched })} |
| 226 | + onEditCompleted={text => triggerOnChange({ |
| 227 | + ...organizationForm.organization, |
| 228 | + email: text |
| 229 | + }, true, { ...organizationForm.touched, email: true })} |
| 230 | + maxLength={maxMailLength} |
| 231 | + className={clsx(inputClasses, { [inputErrorClasses]: isDisplayingEmailNameError })} |
| 232 | + /> |
| 233 | + </div> |
| 234 | + { |
| 235 | + !organizationForm.organization.isVerified && |
| 236 | + <span className="text-negative mb-3">{translation.notVerified}</span> |
| 237 | + } |
202 | 238 | </div> |
203 | | - { |
204 | | - !organizationForm.organization.isVerified && |
205 | | - <span className="text-negative mb-3">{translation.notVerified}</span> |
206 | | - } |
| 239 | + {isDisplayingEmailNameError && <span className="textstyle-form-error">{emailErrorMessage}</span>} |
| 240 | + <span className="textstyle-form-description">{translation.contactEmailDescription}</span> |
207 | 241 | </div> |
208 | | - {isDisplayingEmailNameError && <span className="textstyle-form-error">{emailErrorMessage}</span>} |
209 | 242 | </div> |
210 | | - <span className="textstyle-form-description">{translation.contactEmailDescription}</span> |
211 | 243 | </LoadingAndErrorComponent> |
212 | 244 | ) |
213 | 245 | } |
0 commit comments