Skip to content

Commit

Permalink
[000] set password for user on registration
Browse files Browse the repository at this point in the history
  • Loading branch information
pro100Koss committed Dec 23, 2024
1 parent cf832d0 commit 52ab3a2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import Button from '@/components/ui/Button.tsx';
import apiService from '@/services/ApiService.ts';
import { useToast } from '@/hooks/use-toast.ts';

const schema = z.object({
organizationName: z.string().min(1, 'Organization name is required'),
firstName: z.string().min(1, 'First name is required'),
lastName: z.string().min(1, 'Last name is required'),
email: z.string().email('Invalid email address'),
});
const schema = z
.object({
organizationName: z.string().min(1, 'Organization name is required'),
firstName: z.string().min(1, 'First name is required'),
lastName: z.string().min(1, 'Last name is required'),
email: z.string().email('Invalid email address'),
password: z.string().min(8, 'Password must be at least 8 characters long'),
passwordConfirm: z.string().min(8, 'Password must be at least 8 characters long'),
})
.refine((data) => data.password === data.passwordConfirm, {
message: "Passwords don't match",
path: ['passwordConfirm'],
});

type FormFields = z.infer<typeof schema>;

Expand Down Expand Up @@ -43,6 +50,7 @@ export function OrganizationRegistrationForm(props: Props) {
type: 'EINGETRAGENER_VEREIN',
slug: apiService.organization.createSlug(data.organizationName),
},
newPassword: data.password,
});

showSuccess(t('organization.registration.success'));
Expand All @@ -68,7 +76,12 @@ export function OrganizationRegistrationForm(props: Props) {
<div className="my-4">
<TextField label="Account email" {...register('email')} error={errors.email?.message} />
</div>

<div className="my-4">
<TextField label="Account password" type="password" {...register('password')} error={errors.password?.message} />
</div>
<div className="my-4">
<TextField label="Confirm password" type="password" {...register('passwordConfirm')} error={errors.passwordConfirm?.message} />
</div>
<hr />
<div className="mt-2 text-center">
<Button type="submit">{t('header.register')}</Button>
Expand Down
20 changes: 14 additions & 6 deletions frontend/spa/src/components/views/OrganizationSettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,26 @@ function OrganizationSettingsView() {
}

organizationTreeService.ensureRootBommelCreated(organization.id).then((bommel) => {
setRootBommel(bommel);
if (bommel) {
setRootBommel(bommel);
} else {
setIsOrganizationError(true);
}
});
}, []);

return (
<>
<SettingsPageHeader>
<Button onClick={onClickSave}>Save</Button>
</SettingsPageHeader>
<SettingsPageHeader>{!isOrganizationError && <Button onClick={onClickSave}>Save</Button>}</SettingsPageHeader>

<h3>Structure:</h3>
{isOrganizationError ? <div>Error</div> : <OrganizationTree tree={tree} onTreeChanged={onTreeChanged} />}
{isOrganizationError ? (
<div>{t('organization.settings.error')}</div>
) : (
<>
<h3>Structure:</h3>
<OrganizationTree tree={tree} onTreeChanged={onTreeChanged} />
</>
)}
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/spa/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"success": "Organisation erfolgreich erstellt"
},
"settings": {
"error": "Organisationsstruktur konnte nicht geladen werden",
"saveError": "Einstellung konnte nicht gespeichert werden",
"saved": "Einstellungen erfolgreich gespeichert"
}
Expand Down
1 change: 1 addition & 0 deletions frontend/spa/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"success": "Organisation successfully created"
},
"settings": {
"error": "Failed to load organization structure",
"saveError": "Failed to save setting",
"saved": "Settings successfully saved"
}
Expand Down
1 change: 1 addition & 0 deletions frontend/spa/src/locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"success": "Організацію успішно створено"
},
"settings": {
"error": "Не вдалося завантажити структуру організації",
"saveError": "Не вдалося зберегти налаштування",
"saved": "Налаштування успішно збережені"
}
Expand Down
8 changes: 5 additions & 3 deletions frontend/spa/src/services/OrganizationTreeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,27 @@ export class OrganizationTreeService {
const loadRootBommel = async () => {
return await apiService.bommel.getRootBommel(organizationId);
};

const createRootBommel = async () => {
return await apiService.bommel.createRootBommel({
organization: { id: organizationId },
organizationId,
name: 'root',
emoji: '',
children: [],
parent: undefined,
});
};
try {
let rootBommel = await loadRootBommel();

try {
let rootBommel = await loadRootBommel().catch(() => undefined);
if (!rootBommel) {
rootBommel = await createRootBommel();
}

return rootBommel;
} catch (e) {
console.error('Failed to load root bommel', e);
debugger;

Check failure on line 167 in frontend/spa/src/services/OrganizationTreeService.ts

View workflow job for this annotation

GitHub Actions / build (frontend/spa)

Unexpected 'debugger' statement
return await createRootBommel();
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/spa/src/services/api/BommelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class BommelService {
}

async deleteBommel(id: number) {
await fetch(`${this.baseUrl}/bommel/${id}`, { method: 'DELETE' });
await fetch(`${this.baseUrl}/bommel/${id}?recursive=true`, { method: 'DELETE' });
}

async createBommel(data: Partial<Bommel>) {
Expand All @@ -23,13 +23,13 @@ export class BommelService {
return response.json();
}

async createRootBommel(data: Partial<Bommel> & { organization: { id: number } }) {
async createRootBommel(data: Partial<Bommel> & { organizationId: number }): Promise<Bommel> {
const response = await fetch(`${this.baseUrl}/bommel/root`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
});
return response.json();
return response.status === 200 || response.status === 201 ? response.json() : undefined;
}

async getBommelChildren(id: string) {
Expand Down
1 change: 1 addition & 0 deletions frontend/spa/src/services/api/OrganizationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type RegisterOrganizationPayload = {
lastName: string;
email: string;
};
newPassword: string;
organization: {
profilePicture?: string;
website?: string;
Expand Down

0 comments on commit 52ab3a2

Please sign in to comment.