Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/Pages/AdminPage/AdminPage.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
opacity: 0.5;
}

.mdb_user {
// No styling yet as this will be done whenever the page gets redesigned
}

.preferences_header {
margin-top: 2em;
margin-bottom: 1em;
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/Pages/AdminPage/AdminPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Icon } from '@iconify/react';
import { useTranslation } from 'react-i18next';
import { ToggleSwitch } from '~/Components';
import { Link } from '~/Components';
import { Page } from '~/Components/Page';
import { useAuthContext } from '~/context/AuthContext';
import { useGlobalContext } from '~/context/GlobalContextProvider';
import { useTitle } from '~/hooks';
import { KEY } from '~/i18n/constants';
import { getRandomEntryFromList } from '~/utils';
import { SAMF3_MEMBER_URL } from '~/routes/samf-three';
import { getRandomEntryFromList, lowerCapitalize } from '~/utils';
import styles from './AdminPage.module.scss';
import { WISEWORDS } from './data';

Expand All @@ -28,6 +30,21 @@ export function AdminPage() {
{user?.last_name}
</div>
<p className={styles.wisewords}>{WISEWORD}</p>
{user?.mdb_medlem_id ? (
<div className={styles.mdb_user}>
{`${lowerCapitalize(t(KEY.adminpage_profile_connected_to_mdb))} `}
<Link url={SAMF3_MEMBER_URL.medlem} target="external">
{t(KEY.common_the_member_database)}
</Link>
</div>
) : (
<div className={styles.mdb_user}>
{`${lowerCapitalize(t(KEY.adminpage_profile_not_connected_to_mdb))} `}
<Link url={SAMF3_MEMBER_URL.medlem} target="external">
{t(KEY.common_the_member_database)}
</Link>
</div>
)}
{/* TODO make proper personal landing page with preferences etc */}
<div className={styles.preferences_header}>Preferences</div>
<div className={styles.preference_row}>
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/PagesAdmin/AdminLayout/AdminLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,17 @@ export function AdminLayout() {
</button>
)}
{/** Connect to MDB button */}
<Link
url={ROUTES.frontend.admin_mdb_connect}
className={classNames(styles.panel_item, {
[styles.selected]: location.pathname === ROUTES.frontend.admin_mdb_connect,
})}
>
<Icon icon="mdi:connection" />
{t(KEY.common_member_database)}
</Link>
{!user?.mdb_medlem_id ? (
<Link
url={ROUTES.frontend.admin_mdb_connect}
className={classNames(styles.panel_item, {
[styles.selected]: location.pathname === ROUTES.frontend.admin_mdb_connect,
})}
>
<Icon icon="mdi:connection" />
{t(KEY.common_member_database)}
</Link>
) : null}
{/* Logout */}
<button
type="button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router';
import { toast } from 'react-toastify';
import { z } from 'zod';
import { Input, Link } from '~/Components';
import { Button } from '~/Components/Button';
import { Form, FormField, FormItem, FormLabel } from '~/Components/Forms';
import { FormControl, FormDescription } from '~/Components/Forms/Form';
import { connectToMdb } from '~/api';
import { connectToMdb, getUser } from '~/api';
import { useAuthContext } from '~/context/AuthContext';
import { KEY } from '~/i18n/constants';
import { ROUTES } from '~/routes';
import { SAMF3_MEMBER_URL } from '~/routes/samf-three';
import { EMAIL_OR_MEMBERSHIP_NUMBER, PASSWORD } from '~/schema/user';
import { lowerCapitalize } from '~/utils';
import styles from './MDBConnectFormAdminPage.module.scss';

export function MDBConnectForm() {
const { t } = useTranslation();
const { user, setUser, loading: authLoading } = useAuthContext();
const navigate = useNavigate();

const schema = z.object({
member_login: EMAIL_OR_MEMBERSHIP_NUMBER(t),
Expand All @@ -32,8 +37,11 @@ export function MDBConnectForm() {

function onSubmit(values: z.infer<typeof schema>) {
connectToMdb(values.member_login, values.password)
.then((res) => {
.then(() => getUser())
.then((updatedUser) => {
setUser(updatedUser);
toast.success(t(KEY.adminpage_connect_mdb_succesful_toast));
navigate(ROUTES.frontend.admin);
})
.catch((error) => {
toast.error(t(KEY.adminpage_connect_mdb_common_error));
Expand Down
1 change: 1 addition & 0 deletions frontend/src/dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type UserDto = {
permissions?: string[];
object_permissions?: ObjectPermissionDto[];
role_permissions?: string[];
mdb_medlem_id?: number;
};

export type CampusDto = {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/i18n/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export const KEY = {
common_almost_sold_out: 'common_almost_sold_out',

common_member_database: 'common_member_database',
common_the_member_database: 'common_the_member_database',
// ==================== //
// Others //
// ==================== //
Expand Down Expand Up @@ -601,6 +602,8 @@ export const KEY = {
adminpage_connect_mdb_common_error: 'adminpage_connect_mdb_common_error',
adminpage_connect_mdb_password_notice_1: 'adminpage_connect_mdb_password_notice_1',
adminpage_connect_mdb_password_notice_2: 'adminpage_connect_mdb_password_notice_2',
adminpage_profile_connected_to_mdb: 'adminpage_profile_connected_to_mdb',
adminpage_profile_not_connected_to_mdb: 'adminpage_profile_not_connected_to_mdb',

// CommandMenu:
command_menu_label: 'command_menu_label',
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const nb = prepareTranslations({

// MDB
[KEY.common_member_database]: 'Medlemsdatabase',
[KEY.common_the_member_database]: 'medlemsdatabasen',

// ==================== //
// Others //
Expand Down Expand Up @@ -330,7 +331,7 @@ export const nb = prepareTranslations({
[KEY.adminpage_gangs_title]: 'Administrer gjenger',
[KEY.adminpage_gangs_create]: 'Opprett gjeng',

//MDB Connect AdminPage
//MDB
[KEY.adminpage_connect_mdb]: 'Koble til medlemsdatabasen',
[KEY.adminpage_connect_mdb_succesful_toast]: 'Vellyket tilkobling til medlemsdatabasen',
[KEY.adminpage_connect_mdb_invalid_email]: 'ugyldig e-post',
Expand All @@ -339,6 +340,8 @@ export const nb = prepareTranslations({
'Kunne ikke koble til medlemsdatabasen. Vennligst sjekk at alle felter er skrevet riktig',
[KEY.adminpage_connect_mdb_password_notice_1]: 'Passordet ditt til ',
[KEY.adminpage_connect_mdb_password_notice_2]: 'medlemsdatabasen',
[KEY.adminpage_profile_connected_to_mdb]: 'du er koblet til',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered above

[KEY.adminpage_profile_not_connected_to_mdb]: 'du er ikke koblet til',

// SaksdokumentPage:
[KEY.saksdokumentpage_publication_date]: 'Publiseringsdato',
Expand Down Expand Up @@ -936,6 +939,7 @@ export const en = prepareTranslations({

// MDB
[KEY.common_member_database]: 'Membership database',
[KEY.common_the_member_database]: 'the membership database',
// ==================== //
// Others //
// ==================== //
Expand Down Expand Up @@ -1354,7 +1358,7 @@ export const en = prepareTranslations({
[KEY.feedback_your_feedback]: 'Your feedback',
[KEY.feedback_thank_you_for_feedback]: 'Thank you for your feedback',

//MDB Connect AdminPage
//MDB
[KEY.adminpage_connect_mdb]: 'Connect to the membership database',
[KEY.adminpage_connect_mdb_succesful_toast]: 'Succesfully connected to the membership database',
[KEY.adminpage_connect_mdb_invalid_email]: 'Invalid email',
Expand All @@ -1363,6 +1367,8 @@ export const en = prepareTranslations({
"Couldn't connect to the membership database. Please check that all fields are correct",
[KEY.adminpage_connect_mdb_password_notice_1]: 'Your password to the',
[KEY.adminpage_connect_mdb_password_notice_2]: 'membership database',
[KEY.adminpage_profile_connected_to_mdb]: "you're connected to",
[KEY.adminpage_profile_not_connected_to_mdb]: "you're not connected to",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translation does not fit the key. Should be KEY.adminpage_profile_connected_to or "you're connected to mdb" meybe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, as the key doesn't necessarily need to perfectly fit the translation, but rather tell us what the translation is used for. For example the key-value pair above (adminpage_connect_mdb_password_notice_2 : membership database).

Removing the mdb part from the key would no longer tell us what the translation is supposed to be used for, and it doesn't really fit anywhere else like common


// No category:
[KEY.owner]: 'Owner',
Expand Down
Loading