Skip to content

Commit

Permalink
Merge pull request #601 from code4romania/feature/590-role
Browse files Browse the repository at this point in the history
feat: [590] add role for contact entity
  • Loading branch information
dragos1195 authored Jul 31, 2024
2 parents bdd7362 + 0d55b53 commit 64ac077
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 4 deletions.
13 changes: 13 additions & 0 deletions backend/src/migrations/1722423180665-ContactRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class ContactRole1722423180665 implements MigrationInterface {
name = 'ContactRole1722423180665';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "_contact" ADD "role" text`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "_contact" DROP COLUMN "role"`);
}
}
5 changes: 5 additions & 0 deletions backend/src/modules/organization/dto/create-contact.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ export class CreateContactDto {
@IsNotEmpty()
@MaxLength(50)
email: string;

@IsOptional()
@IsString()
@MaxLength(50)
role: string;
}
3 changes: 3 additions & 0 deletions backend/src/modules/organization/entities/contact.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export class Contact extends BaseEntity {
@Column({ type: 'text', name: 'phone', nullable: true })
phone: string;

@Column({ type: 'text', name: 'role', nullable: true })
role: string;

@ManyToMany(
(type) => OrganizationLegal,
(organizationLegal) => organizationLegal.directors,
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/assets/locales/ro/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@
"name": "Nume și prenume",
"role": "Rol",
"email": "E-mail",
"phone": "Telefon"
"phone": "Telefon",
"role": "Rol"
},
"legal_config": {
"name": {
Expand All @@ -607,6 +608,10 @@
"minim": "Numărul de telefon al reprezentantului legal nu poate avea mai puțin de 10 caractere.",
"invalid": "Numărul de telefon are un format invalid.",
"label": "Telefon"
},
"role": {
"maxim": "Rolul reprezentantului legal nu poate avea mai mult de 50 de caractere.",
"label": "Rol"
}
},
"director_config": {
Expand All @@ -629,6 +634,10 @@
"minim": "Numărul de telefon al membrului Consiliului Director nu poate avea mai puțin de 10 caractere.",
"invalid": "Numărul de telefon are un format invalid.",
"label": "Telefon"
},
"role": {
"maxim": "Rolul membrului Consiliului Director nu poate avea mai mult de 50 de caractere.",
"label": "Rol"
}
},
"other_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const CreateOrganizationLegal = () => {
fullName: legal.legalReprezentative_fullName,
phone: legal.legalReprezentative_phone,
email: legal.legalReprezentative_email,
role: legal.legalReprezentative_role,
};

//Using isValidating because RHF triggers 2 renders and update local storage with invalid data
Expand Down Expand Up @@ -184,7 +185,8 @@ const CreateOrganizationLegal = () => {
!(
director.fullName === selectedDirector?.fullName &&
director.email === selectedDirector?.email &&
director.phone === selectedDirector?.phone
director.phone === selectedDirector?.phone &&
director.role === selectedDirector?.role
),
);
setDirectors([...filteredDirectors, { ...selectedDirector, ...contact }]);
Expand All @@ -206,7 +208,8 @@ const CreateOrganizationLegal = () => {
!(
director.fullName === selectedDirector?.fullName &&
director.email === selectedDirector?.email &&
director.phone === selectedDirector?.phone
director.phone === selectedDirector?.phone &&
director.role === selectedDirector?.role
),
);
setDirectors(filteredDirectors);
Expand Down Expand Up @@ -303,6 +306,7 @@ const CreateOrganizationLegal = () => {
OrganizationLegalConfig.legal_reprezentative_name,
OrganizationLegalConfig.legal_reprezentative_email,
OrganizationLegalConfig.legal_reprezentative_phone,
OrganizationLegalConfig.legal_reprezentative_role,
]}
id="create-organization-legal"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ const OrganizationLegal = () => {
fullName: data.legalReprezentative_fullName,
phone: data.legalReprezentative_phone,
email: data.legalReprezentative_email,
role: data.legalReprezentative_role,
};

updateOrganization(
Expand Down Expand Up @@ -427,6 +428,7 @@ const OrganizationLegal = () => {
OrganizationLegalConfig.legal_reprezentative_name,
OrganizationLegalConfig.legal_reprezentative_email,
OrganizationLegalConfig.legal_reprezentative_phone,
OrganizationLegalConfig.legal_reprezentative_role,
]}
/>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const translations = {
invalid: i18n.t('legal:legal_config.phone.invalid'),
phone: i18n.t('legal:legal_config.phone.label'),
},
role: {
maxim: i18n.t('legal:legal_config.role.maxim'),
role: i18n.t('legal:legal_config.role.label'),
},
};

export const OrganizationLegalConfig: Record<string, any> = {
Expand Down Expand Up @@ -98,4 +102,19 @@ export const OrganizationLegalConfig: Record<string, any> = {
placeholder: '',
},
},
legal_reprezentative_role: {
key: 'legalReprezentative_role',
rules: {
maxLength: {
value: 50,
message: translations.role.maxim,
},
},
config: {
type: 'text',
label: translations.role.role,
helperText: '',
placeholder: 'Administrator',
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const translations = {
invalid: i18n.t('legal:director_config.phone.invalid'),
phone: i18n.t('legal:director_config.phone.label'),
},
role: {
maxim: i18n.t('legal:director_config.role.maxim'),
role: i18n.t('legal:director_config.role.label'),
},
};

export const DirectorConfig: Record<string, any> = {
Expand Down Expand Up @@ -98,4 +102,19 @@ export const DirectorConfig: Record<string, any> = {
placeholder: '0721111111',
},
},
role: {
key: 'role',
rules: {
maxLength: {
value: 50,
message: translations.phone.maxim,
},
},
config: {
type: 'text',
label: i18n.t('legal:director_config.role.label'),
helperText: '',
placeholder: 'Administrator',
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const DirectorModal = ({ isEdit, onClose, defaultValue, onSave, id }: DirectorMo
control={control}
errors={errors}
readonly={false}
configs={[DirectorConfig.fullName, DirectorConfig.email, DirectorConfig.phone]}
configs={[DirectorConfig.fullName, DirectorConfig.email, DirectorConfig.phone, DirectorConfig.role]}
id={id}
/>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const translations = {
name: i18n.t('legal:header.name'),
email: i18n.t('legal:header.email'),
phone: i18n.t('legal:header.phone'),
role: i18n.t('legal:header.role'),
};

export const DirectorsTableHeaders: TableColumn<Contact>[] = [
Expand Down Expand Up @@ -35,4 +36,12 @@ export const DirectorsTableHeaders: TableColumn<Contact>[] = [
minWidth: '10rem',
sortable: true,
},
{
id: 'role',
name: <DataTableNameHeader text={translations.role} />,
selector: (row: Contact) => row.role,
grow: 1,
minWidth: '10rem',
sortable: true,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface Contact extends BaseEntity {
fullName: string;
email: string;
phone: string;
role: string;
}

0 comments on commit 64ac077

Please sign in to comment.