Skip to content

Commit

Permalink
added type and added initial value to form
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo1212 committed Nov 6, 2023
1 parent a9379a7 commit c41a128
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
10 changes: 7 additions & 3 deletions src/components/users/AddUserToAbteilung.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {AbteilungenContext} from "../navigation/NavigationMenu";
import {roles} from "../abteilung/members/MemberTable";
import {useForm} from "antd/es/form/Form";
import Modal from "antd/lib/modal/Modal";
import { AbteilungMember } from 'types/user.type';

export interface EditAbteilungMemberProps {
uid: string
Expand All @@ -16,7 +17,7 @@ export const AddUserToAbteilung = (props: EditAbteilungMemberProps) => {

const {uid, onSuccess} = props;

const [form] = useForm();
const [form] = useForm<AbteilungMember>();

const abteilungenContext = useContext(AbteilungenContext);
const abteilungen = abteilungenContext.abteilungen;
Expand All @@ -28,7 +29,7 @@ export const AddUserToAbteilung = (props: EditAbteilungMemberProps) => {
if (memberDoc.exists) {
message.error('Dieser Benutzer ist bereits mitglied dieser Abteilung');
} else {
const member = {
const member: AbteilungMember = {
userId: uid,
role: form.getFieldValue('role'),
approved: true,
Expand All @@ -50,6 +51,9 @@ export const AddUserToAbteilung = (props: EditAbteilungMemberProps) => {
abtielungenLoading ? <Spin/> : <>
<Form
form={form}
initialValues={{
role: 'member'
} as Partial<AbteilungMember>}
onFinish={addUserToAbteilung}>
<Form.Item
label='Abteilung'
Expand Down Expand Up @@ -79,7 +83,7 @@ export const AddUserToAbteilung = (props: EditAbteilungMemberProps) => {
{required: true}
]}
>
<Select key='role' defaultValue='member'>
<Select key='role'>
{
roles.map(role => <Select.Option key={role.key}
value={role.key}>{role.name}</Select.Option>)
Expand Down
52 changes: 29 additions & 23 deletions src/types/user.type.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
export interface UserData {
__caslSubjectType__ : 'UserData'
id: string;
email: string
displayName: string
photoURL: string
given_name: string,
family_name: string,
nickname: string,
name: string,
email_verified?: boolean
user_metadata?: any
staff?: boolean;
defaultAbteilung?: string;
roles: { [abteilungId: string]: role }
__caslSubjectType__: "UserData";
id: string;
email: string;
displayName: string;
photoURL: string;
given_name: string;
family_name: string;
nickname: string;
name: string;
email_verified?: boolean;
user_metadata?: any;
staff?: boolean;
defaultAbteilung?: string;
roles: { [abteilungId: string]: role };
}

export interface UserDataUpdate {
email: string
displayName: string
photoURL: string
given_name: string,
family_name: string,
nickname: string,
name: string,
defaultAbteilung?: string;
email: string;
displayName: string;
photoURL: string;
given_name: string;
family_name: string;
nickname: string;
name: string;
defaultAbteilung?: string;
}

export type role = 'pending' | 'guest' | 'member' | 'matchef' | 'admin';
export type role = "pending" | "guest" | "member" | "matchef" | "admin";

export interface AbteilungMember {
userId: string;
role: role;
approved: boolean;
}

0 comments on commit c41a128

Please sign in to comment.