From b5bc94793b77bdfe81eb93af0ce7eaf36205e5c8 Mon Sep 17 00:00:00 2001 From: Mai-ly Date: Wed, 15 Feb 2023 10:07:22 +0100 Subject: [PATCH 1/5] :monocle_face: add notification table --- hasura/metadata/tables.yaml | 17 +++++++++++++++-- .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 4 ++++ .../up.sql | 2 ++ .../down.sql | 4 ++++ .../up.sql | 2 ++ .../down.sql | 4 ++++ .../up.sql | 2 ++ .../down.sql | 1 + .../up.sql | 1 + 11 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 hasura/migrations/1676386301089_create_table_public_UserNotifications/down.sql create mode 100644 hasura/migrations/1676386301089_create_table_public_UserNotifications/up.sql create mode 100644 hasura/migrations/1676386537092_alter_table_public_UserNotifications_add_column_created_at/down.sql create mode 100644 hasura/migrations/1676386537092_alter_table_public_UserNotifications_add_column_created_at/up.sql create mode 100644 hasura/migrations/1676386757076_alter_table_public_UserNotifications_add_column_skill_id/down.sql create mode 100644 hasura/migrations/1676386757076_alter_table_public_UserNotifications_add_column_skill_id/up.sql create mode 100644 hasura/migrations/1676386844964_alter_table_public_UserNotifications_add_column_notification_type/down.sql create mode 100644 hasura/migrations/1676386844964_alter_table_public_UserNotifications_add_column_notification_type/up.sql create mode 100644 hasura/migrations/1676387350118_alter_table_public_UserNotifications_update_comment/down.sql create mode 100644 hasura/migrations/1676387350118_alter_table_public_UserNotifications_update_comment/up.sql diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index dbd74e47..784e3868 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -516,6 +516,19 @@ - agency filter: {} allow_aggregations: true +- table: + schema: public + name: UserNotifications + object_relationships: + - name: skill + using: + manual_configuration: + remote_table: + schema: public + name: Skill + insertion_order: null + column_mapping: + skill_id: id - table: schema: public name: UserSkillDesire @@ -577,7 +590,7 @@ definition: enable_manual: false insert: - columns: "*" + columns: '*' retry_conf: num_retries: 5 interval_sec: 30 @@ -640,7 +653,7 @@ definition: enable_manual: false insert: - columns: "*" + columns: '*' retry_conf: num_retries: 5 interval_sec: 30 diff --git a/hasura/migrations/1676386301089_create_table_public_UserNotifications/down.sql b/hasura/migrations/1676386301089_create_table_public_UserNotifications/down.sql new file mode 100644 index 00000000..f1eca018 --- /dev/null +++ b/hasura/migrations/1676386301089_create_table_public_UserNotifications/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."UserNotifications"; diff --git a/hasura/migrations/1676386301089_create_table_public_UserNotifications/up.sql b/hasura/migrations/1676386301089_create_table_public_UserNotifications/up.sql new file mode 100644 index 00000000..1648d6e8 --- /dev/null +++ b/hasura/migrations/1676386301089_create_table_public_UserNotifications/up.sql @@ -0,0 +1 @@ +CREATE TABLE "public"."UserNotifications" ("id" uuid NOT NULL, "checked" boolean NOT NULL, "user_email" text NOT NULL, PRIMARY KEY ("id") , UNIQUE ("id"));COMMENT ON TABLE "public"."UserNotifications" IS E'Skill verified - last skills'; diff --git a/hasura/migrations/1676386537092_alter_table_public_UserNotifications_add_column_created_at/down.sql b/hasura/migrations/1676386537092_alter_table_public_UserNotifications_add_column_created_at/down.sql new file mode 100644 index 00000000..9a333bb9 --- /dev/null +++ b/hasura/migrations/1676386537092_alter_table_public_UserNotifications_add_column_created_at/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."UserNotifications" add column "created_at" date +-- not null default now(); diff --git a/hasura/migrations/1676386537092_alter_table_public_UserNotifications_add_column_created_at/up.sql b/hasura/migrations/1676386537092_alter_table_public_UserNotifications_add_column_created_at/up.sql new file mode 100644 index 00000000..90a8ee9e --- /dev/null +++ b/hasura/migrations/1676386537092_alter_table_public_UserNotifications_add_column_created_at/up.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" add column "created_at" date + not null default now(); diff --git a/hasura/migrations/1676386757076_alter_table_public_UserNotifications_add_column_skill_id/down.sql b/hasura/migrations/1676386757076_alter_table_public_UserNotifications_add_column_skill_id/down.sql new file mode 100644 index 00000000..6ef16155 --- /dev/null +++ b/hasura/migrations/1676386757076_alter_table_public_UserNotifications_add_column_skill_id/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."UserNotifications" add column "skill_id" uuid +-- not null; diff --git a/hasura/migrations/1676386757076_alter_table_public_UserNotifications_add_column_skill_id/up.sql b/hasura/migrations/1676386757076_alter_table_public_UserNotifications_add_column_skill_id/up.sql new file mode 100644 index 00000000..8c5c7e72 --- /dev/null +++ b/hasura/migrations/1676386757076_alter_table_public_UserNotifications_add_column_skill_id/up.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" add column "skill_id" uuid + not null; diff --git a/hasura/migrations/1676386844964_alter_table_public_UserNotifications_add_column_notification_type/down.sql b/hasura/migrations/1676386844964_alter_table_public_UserNotifications_add_column_notification_type/down.sql new file mode 100644 index 00000000..bd658de4 --- /dev/null +++ b/hasura/migrations/1676386844964_alter_table_public_UserNotifications_add_column_notification_type/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."UserNotifications" add column "notification_type" text +-- not null; diff --git a/hasura/migrations/1676386844964_alter_table_public_UserNotifications_add_column_notification_type/up.sql b/hasura/migrations/1676386844964_alter_table_public_UserNotifications_add_column_notification_type/up.sql new file mode 100644 index 00000000..dc7ef022 --- /dev/null +++ b/hasura/migrations/1676386844964_alter_table_public_UserNotifications_add_column_notification_type/up.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" add column "notification_type" text + not null; diff --git a/hasura/migrations/1676387350118_alter_table_public_UserNotifications_update_comment/down.sql b/hasura/migrations/1676387350118_alter_table_public_UserNotifications_update_comment/down.sql new file mode 100644 index 00000000..2af384be --- /dev/null +++ b/hasura/migrations/1676387350118_alter_table_public_UserNotifications_update_comment/down.sql @@ -0,0 +1 @@ +comment on table "public"."UserNotifications" is NULL; diff --git a/hasura/migrations/1676387350118_alter_table_public_UserNotifications_update_comment/up.sql b/hasura/migrations/1676387350118_alter_table_public_UserNotifications_update_comment/up.sql new file mode 100644 index 00000000..2af384be --- /dev/null +++ b/hasura/migrations/1676387350118_alter_table_public_UserNotifications_update_comment/up.sql @@ -0,0 +1 @@ +comment on table "public"."UserNotifications" is NULL; From 002e1f15b90a487dc55ee47b543078b0025eb6fc Mon Sep 17 00:00:00 2001 From: Mai-ly Date: Mon, 20 Feb 2023 14:07:10 +0100 Subject: [PATCH 2/5] :card_file_box: add mutations and metadata new fields --- doc/rg.md | 4 + hasura/metadata/tables.yaml | 140 +++++++++--------- .../down.sql | 4 + .../up.sql | 2 + .../down.sql | 4 + .../up.sql | 2 + .../down.sql | 4 + .../up.sql | 2 + .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 2 + .../up.sql | 1 + .../down.sql | 2 + .../up.sql | 1 + .../down.sql | 4 + .../up.sql | 2 + .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 1 + .../up.sql | 1 + .../down.sql | 2 + .../up.sql | 1 + .../organisms/AddSkilListSelector.tsx | 15 +- src/components/organisms/EditSkillAdmin.tsx | 21 ++- src/graphql/mutations/notifications.ts | 21 +++ src/graphql/mutations/skills.ts | 20 ++- src/graphql/queries/notifications.ts | 17 +++ src/graphql/queries/skills.ts | 1 + 28 files changed, 192 insertions(+), 86 deletions(-) create mode 100644 hasura/migrations/1676456093489_alter_table_public_UserNotifications_add_column_admin_email/down.sql create mode 100644 hasura/migrations/1676456093489_alter_table_public_UserNotifications_add_column_admin_email/up.sql create mode 100644 hasura/migrations/1676468229753_alter_table_public_Skill_add_column_creator/down.sql create mode 100644 hasura/migrations/1676468229753_alter_table_public_Skill_add_column_creator/up.sql create mode 100644 hasura/migrations/1676468549770_alter_table_public_UserNotifications_add_column_notification_id/down.sql create mode 100644 hasura/migrations/1676468549770_alter_table_public_UserNotifications_add_column_notification_id/up.sql create mode 100644 hasura/migrations/1676468692774_alter_table_public_UserNotifications_alter_column_id/down.sql create mode 100644 hasura/migrations/1676468692774_alter_table_public_UserNotifications_alter_column_id/up.sql create mode 100644 hasura/migrations/1676468726804_alter_table_public_UserNotifications_drop_column_notification_type/down.sql create mode 100644 hasura/migrations/1676468726804_alter_table_public_UserNotifications_drop_column_notification_type/up.sql create mode 100644 hasura/migrations/1676468855008_alter_table_public_UserNotifications_drop_column_notification_id/down.sql create mode 100644 hasura/migrations/1676468855008_alter_table_public_UserNotifications_drop_column_notification_id/up.sql create mode 100644 hasura/migrations/1676468906231_alter_table_public_UserNotifications_add_column_notification_id/down.sql create mode 100644 hasura/migrations/1676468906231_alter_table_public_UserNotifications_add_column_notification_id/up.sql create mode 100644 hasura/migrations/1676469920879_rename_table_public_UserNotifications/down.sql create mode 100644 hasura/migrations/1676469920879_rename_table_public_UserNotifications/up.sql create mode 100644 hasura/migrations/1676470397300_rename_table_public_Notifications/down.sql create mode 100644 hasura/migrations/1676470397300_rename_table_public_Notifications/up.sql create mode 100644 hasura/migrations/1676470552127_alter_table_public_UserNotifications_drop_column_notification_id/down.sql create mode 100644 hasura/migrations/1676470552127_alter_table_public_UserNotifications_drop_column_notification_id/up.sql create mode 100644 src/graphql/mutations/notifications.ts create mode 100644 src/graphql/queries/notifications.ts diff --git a/doc/rg.md b/doc/rg.md index d3b72df6..4d202f55 100644 --- a/doc/rg.md +++ b/doc/rg.md @@ -11,3 +11,7 @@ ### MG_TUTORIAL_MODE > If the user has no skill in base, the tutorial mode will be automatically set as true + +### MG_NOTIFICATIONS + +> If admin approve a skill added by a user, the user receive a notification diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index 784e3868..bbd2a3da 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -1,6 +1,6 @@ - table: - schema: public name: AgenciesAverageCurrentSkillsAndDesires + schema: public select_permissions: - role: world permission: @@ -15,16 +15,16 @@ filter: {} allow_aggregations: true - table: - schema: public name: Agency + schema: public array_relationships: - name: UserAgencies using: foreign_key_constraint_on: column: agency table: - schema: public name: UserAgency + schema: public select_permissions: - role: world permission: @@ -33,43 +33,43 @@ filter: {} allow_aggregations: true - table: - schema: public name: Category + schema: public array_relationships: - name: AgenciesAverageCurrentSkillsAndDesires using: manual_configuration: - remote_table: - schema: public - name: AgenciesAverageCurrentSkillsAndDesires - insertion_order: null column_mapping: id: categoryId + insertion_order: null + remote_table: + name: AgenciesAverageCurrentSkillsAndDesires + schema: public - name: CurrentSkillsAndDesires using: manual_configuration: - remote_table: - schema: public - name: UsersCurrentSkillsAndDesires - insertion_order: null column_mapping: id: categoryId + insertion_order: null + remote_table: + name: UsersCurrentSkillsAndDesires + schema: public - name: Skills using: foreign_key_constraint_on: column: categoryId table: - schema: public name: Skill + schema: public - name: ZenikasAverageCurrentSkillsAndDesires using: manual_configuration: - remote_table: - schema: public - name: ZenikasAverageCurrentSkillsAndDesires - insertion_order: null column_mapping: id: categoryId + insertion_order: null + remote_table: + name: ZenikasAverageCurrentSkillsAndDesires + schema: public select_permissions: - role: world permission: @@ -96,8 +96,8 @@ filter: {} check: {} - table: - schema: public name: Certification + schema: public select_permissions: - role: world permission: @@ -109,11 +109,11 @@ filter: {} allow_aggregations: true - table: - schema: public name: CertificationSkill -- table: schema: public +- table: name: Skill + schema: public object_relationships: - name: Category using: @@ -124,45 +124,47 @@ foreign_key_constraint_on: column: skillId table: - schema: public name: SkillTag + schema: public - name: SkillTopics using: foreign_key_constraint_on: column: skillId table: - schema: public name: SkillTopic + schema: public - name: UserSkillDesires using: foreign_key_constraint_on: column: skillId table: - schema: public name: UserSkillDesire + schema: public - name: UsersCurrentSkillsAndDesires using: manual_configuration: - remote_table: - schema: public - name: UsersCurrentSkillsAndDesires - insertion_order: null column_mapping: id: skillId + insertion_order: null + remote_table: + name: UsersCurrentSkillsAndDesires + schema: public insert_permissions: - role: world permission: check: {} columns: - categoryId + - creator - id - - verified - name + - verified select_permissions: - role: world permission: columns: - categoryId + - creator - description - id - name @@ -183,11 +185,10 @@ delete_permissions: - role: world permission: - backend_only: false filter: {} - table: - schema: public name: SkillTag + schema: public object_relationships: - name: Skill using: @@ -212,11 +213,10 @@ delete_permissions: - role: world permission: - backend_only: false filter: {} - table: - schema: public name: SkillTopic + schema: public object_relationships: - name: Skill using: @@ -247,19 +247,18 @@ delete_permissions: - role: world permission: - backend_only: false filter: {} - table: - schema: public name: Tag + schema: public array_relationships: - name: SkillTags using: foreign_key_constraint_on: column: tagId table: - schema: public name: SkillTag + schema: public insert_permissions: - role: world permission: @@ -275,23 +274,23 @@ - name filter: {} - table: - schema: public name: Topic + schema: public array_relationships: - name: SkillTopics using: foreign_key_constraint_on: column: topicId table: - schema: public name: SkillTopic + schema: public - name: UserTopics using: foreign_key_constraint_on: column: topicId table: - schema: public name: UserTopic + schema: public select_permissions: - role: world permission: @@ -302,40 +301,40 @@ filter: {} allow_aggregations: true - table: - schema: public name: User + schema: public object_relationships: - name: UserLatestAgency using: manual_configuration: - remote_table: - schema: public - name: UserLatestAgency - insertion_order: null column_mapping: email: userEmail + insertion_order: null + remote_table: + name: UserLatestAgency + schema: public array_relationships: - name: UserAgencies using: foreign_key_constraint_on: column: userEmail table: - schema: public name: UserAgency + schema: public - name: UserSkillDesires using: foreign_key_constraint_on: column: userEmail table: - schema: public name: UserSkillDesire + schema: public - name: UserTopics using: foreign_key_constraint_on: column: userEmail table: - schema: public name: UserTopic + schema: public insert_permissions: - role: world permission: @@ -376,8 +375,8 @@ _eq: x-hasura-user-email check: null - table: - schema: public name: UserAchievements + schema: public object_relationships: - name: User using: @@ -413,8 +412,8 @@ userEmail: _eq: x-hasura-user-email - table: - schema: public name: UserAgency + schema: public object_relationships: - name: Agency using: @@ -455,8 +454,8 @@ userEmail: _eq: x-hasura-user-email - table: - schema: public name: UserCertification + schema: public object_relationships: - name: Certification using: @@ -501,13 +500,12 @@ delete_permissions: - role: world permission: - backend_only: false filter: userEmail: _eq: x-hasura-user-email - table: - schema: public name: UserLatestAgency + schema: public select_permissions: - role: world permission: @@ -517,21 +515,21 @@ filter: {} allow_aggregations: true - table: - schema: public name: UserNotifications + schema: public object_relationships: - name: skill using: manual_configuration: - remote_table: - schema: public - name: Skill - insertion_order: null column_mapping: skill_id: id + insertion_order: null + remote_table: + name: Skill + schema: public - table: - schema: public name: UserSkillDesire + schema: public object_relationships: - name: Skill using: @@ -581,7 +579,6 @@ delete_permissions: - role: world permission: - backend_only: false filter: userEmail: _eq: x-hasura-user-email @@ -592,16 +589,16 @@ insert: columns: '*' retry_conf: - num_retries: 5 interval_sec: 30 + num_retries: 5 timeout_sec: 60 webhook_from_env: HASURA_ACHIEVEMENTS_ENDPOINT headers: - name: authorization value_from_env: NEXT_API_BEARER_TOKEN - table: - schema: public name: UserTopic + schema: public object_relationships: - name: Topic using: @@ -644,7 +641,6 @@ delete_permissions: - role: world permission: - backend_only: false filter: userEmail: _eq: x-hasura-user-email @@ -655,26 +651,26 @@ insert: columns: '*' retry_conf: - num_retries: 5 interval_sec: 30 + num_retries: 5 timeout_sec: 60 webhook_from_env: HASURA_ACHIEVEMENTS_ENDPOINT headers: - name: authorization value_from_env: NEXT_API_BEARER_TOKEN - table: - schema: public name: UsersCurrentSkillsAndDesires + schema: public object_relationships: - name: User using: manual_configuration: - remote_table: - schema: public - name: User - insertion_order: null column_mapping: userEmail: email + insertion_order: null + remote_table: + name: User + schema: public select_permissions: - role: world permission: @@ -689,18 +685,18 @@ filter: {} allow_aggregations: true - table: - schema: public name: ZenikasAverageCurrentSkillsAndDesires + schema: public object_relationships: - name: Category using: manual_configuration: - remote_table: - schema: public - name: Category - insertion_order: null column_mapping: categoryId: id + insertion_order: null + remote_table: + name: Category + schema: public select_permissions: - role: world permission: diff --git a/hasura/migrations/1676456093489_alter_table_public_UserNotifications_add_column_admin_email/down.sql b/hasura/migrations/1676456093489_alter_table_public_UserNotifications_add_column_admin_email/down.sql new file mode 100644 index 00000000..65ddf0c9 --- /dev/null +++ b/hasura/migrations/1676456093489_alter_table_public_UserNotifications_add_column_admin_email/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."UserNotifications" add column "admin_email" text +-- not null; diff --git a/hasura/migrations/1676456093489_alter_table_public_UserNotifications_add_column_admin_email/up.sql b/hasura/migrations/1676456093489_alter_table_public_UserNotifications_add_column_admin_email/up.sql new file mode 100644 index 00000000..4789b2ae --- /dev/null +++ b/hasura/migrations/1676456093489_alter_table_public_UserNotifications_add_column_admin_email/up.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" add column "admin_email" text + not null; diff --git a/hasura/migrations/1676468229753_alter_table_public_Skill_add_column_creator/down.sql b/hasura/migrations/1676468229753_alter_table_public_Skill_add_column_creator/down.sql new file mode 100644 index 00000000..c3d1d953 --- /dev/null +++ b/hasura/migrations/1676468229753_alter_table_public_Skill_add_column_creator/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."Skill" add column "creator" text +-- null; diff --git a/hasura/migrations/1676468229753_alter_table_public_Skill_add_column_creator/up.sql b/hasura/migrations/1676468229753_alter_table_public_Skill_add_column_creator/up.sql new file mode 100644 index 00000000..9e2cbb23 --- /dev/null +++ b/hasura/migrations/1676468229753_alter_table_public_Skill_add_column_creator/up.sql @@ -0,0 +1,2 @@ +alter table "public"."Skill" add column "creator" text + null; diff --git a/hasura/migrations/1676468549770_alter_table_public_UserNotifications_add_column_notification_id/down.sql b/hasura/migrations/1676468549770_alter_table_public_UserNotifications_add_column_notification_id/down.sql new file mode 100644 index 00000000..c732b6f5 --- /dev/null +++ b/hasura/migrations/1676468549770_alter_table_public_UserNotifications_add_column_notification_id/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."UserNotifications" add column "notification_id" uuid +-- not null; diff --git a/hasura/migrations/1676468549770_alter_table_public_UserNotifications_add_column_notification_id/up.sql b/hasura/migrations/1676468549770_alter_table_public_UserNotifications_add_column_notification_id/up.sql new file mode 100644 index 00000000..a225e064 --- /dev/null +++ b/hasura/migrations/1676468549770_alter_table_public_UserNotifications_add_column_notification_id/up.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" add column "notification_id" uuid + not null; diff --git a/hasura/migrations/1676468692774_alter_table_public_UserNotifications_alter_column_id/down.sql b/hasura/migrations/1676468692774_alter_table_public_UserNotifications_alter_column_id/down.sql new file mode 100644 index 00000000..74d0b214 --- /dev/null +++ b/hasura/migrations/1676468692774_alter_table_public_UserNotifications_alter_column_id/down.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."UserNotifications" ALTER COLUMN "id" drop default; diff --git a/hasura/migrations/1676468692774_alter_table_public_UserNotifications_alter_column_id/up.sql b/hasura/migrations/1676468692774_alter_table_public_UserNotifications_alter_column_id/up.sql new file mode 100644 index 00000000..e2943263 --- /dev/null +++ b/hasura/migrations/1676468692774_alter_table_public_UserNotifications_alter_column_id/up.sql @@ -0,0 +1 @@ +alter table "public"."UserNotifications" alter column "id" set default gen_random_uuid(); diff --git a/hasura/migrations/1676468726804_alter_table_public_UserNotifications_drop_column_notification_type/down.sql b/hasura/migrations/1676468726804_alter_table_public_UserNotifications_drop_column_notification_type/down.sql new file mode 100644 index 00000000..364bbb9d --- /dev/null +++ b/hasura/migrations/1676468726804_alter_table_public_UserNotifications_drop_column_notification_type/down.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" alter column "notification_type" drop not null; +alter table "public"."UserNotifications" add column "notification_type" text; diff --git a/hasura/migrations/1676468726804_alter_table_public_UserNotifications_drop_column_notification_type/up.sql b/hasura/migrations/1676468726804_alter_table_public_UserNotifications_drop_column_notification_type/up.sql new file mode 100644 index 00000000..4bd3401d --- /dev/null +++ b/hasura/migrations/1676468726804_alter_table_public_UserNotifications_drop_column_notification_type/up.sql @@ -0,0 +1 @@ +alter table "public"."UserNotifications" drop column "notification_type" cascade; diff --git a/hasura/migrations/1676468855008_alter_table_public_UserNotifications_drop_column_notification_id/down.sql b/hasura/migrations/1676468855008_alter_table_public_UserNotifications_drop_column_notification_id/down.sql new file mode 100644 index 00000000..c2c4dd8f --- /dev/null +++ b/hasura/migrations/1676468855008_alter_table_public_UserNotifications_drop_column_notification_id/down.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" alter column "notification_id" drop not null; +alter table "public"."UserNotifications" add column "notification_id" uuid; diff --git a/hasura/migrations/1676468855008_alter_table_public_UserNotifications_drop_column_notification_id/up.sql b/hasura/migrations/1676468855008_alter_table_public_UserNotifications_drop_column_notification_id/up.sql new file mode 100644 index 00000000..4fb1725f --- /dev/null +++ b/hasura/migrations/1676468855008_alter_table_public_UserNotifications_drop_column_notification_id/up.sql @@ -0,0 +1 @@ +alter table "public"."UserNotifications" drop column "notification_id" cascade; diff --git a/hasura/migrations/1676468906231_alter_table_public_UserNotifications_add_column_notification_id/down.sql b/hasura/migrations/1676468906231_alter_table_public_UserNotifications_add_column_notification_id/down.sql new file mode 100644 index 00000000..671748a4 --- /dev/null +++ b/hasura/migrations/1676468906231_alter_table_public_UserNotifications_add_column_notification_id/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."UserNotifications" add column "notification_id" integer +-- not null; diff --git a/hasura/migrations/1676468906231_alter_table_public_UserNotifications_add_column_notification_id/up.sql b/hasura/migrations/1676468906231_alter_table_public_UserNotifications_add_column_notification_id/up.sql new file mode 100644 index 00000000..3c278bc0 --- /dev/null +++ b/hasura/migrations/1676468906231_alter_table_public_UserNotifications_add_column_notification_id/up.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" add column "notification_id" integer + not null; diff --git a/hasura/migrations/1676469920879_rename_table_public_UserNotifications/down.sql b/hasura/migrations/1676469920879_rename_table_public_UserNotifications/down.sql new file mode 100644 index 00000000..a9315eaa --- /dev/null +++ b/hasura/migrations/1676469920879_rename_table_public_UserNotifications/down.sql @@ -0,0 +1 @@ +alter table "public"."Notifications" rename to "UserNotifications"; diff --git a/hasura/migrations/1676469920879_rename_table_public_UserNotifications/up.sql b/hasura/migrations/1676469920879_rename_table_public_UserNotifications/up.sql new file mode 100644 index 00000000..8dc6f97a --- /dev/null +++ b/hasura/migrations/1676469920879_rename_table_public_UserNotifications/up.sql @@ -0,0 +1 @@ +alter table "public"."UserNotifications" rename to "Notifications"; diff --git a/hasura/migrations/1676470397300_rename_table_public_Notifications/down.sql b/hasura/migrations/1676470397300_rename_table_public_Notifications/down.sql new file mode 100644 index 00000000..8dc6f97a --- /dev/null +++ b/hasura/migrations/1676470397300_rename_table_public_Notifications/down.sql @@ -0,0 +1 @@ +alter table "public"."UserNotifications" rename to "Notifications"; diff --git a/hasura/migrations/1676470397300_rename_table_public_Notifications/up.sql b/hasura/migrations/1676470397300_rename_table_public_Notifications/up.sql new file mode 100644 index 00000000..a9315eaa --- /dev/null +++ b/hasura/migrations/1676470397300_rename_table_public_Notifications/up.sql @@ -0,0 +1 @@ +alter table "public"."Notifications" rename to "UserNotifications"; diff --git a/hasura/migrations/1676470552127_alter_table_public_UserNotifications_drop_column_notification_id/down.sql b/hasura/migrations/1676470552127_alter_table_public_UserNotifications_drop_column_notification_id/down.sql new file mode 100644 index 00000000..a65157a4 --- /dev/null +++ b/hasura/migrations/1676470552127_alter_table_public_UserNotifications_drop_column_notification_id/down.sql @@ -0,0 +1,2 @@ +alter table "public"."UserNotifications" alter column "notification_id" drop not null; +alter table "public"."UserNotifications" add column "notification_id" int4; diff --git a/hasura/migrations/1676470552127_alter_table_public_UserNotifications_drop_column_notification_id/up.sql b/hasura/migrations/1676470552127_alter_table_public_UserNotifications_drop_column_notification_id/up.sql new file mode 100644 index 00000000..4fb1725f --- /dev/null +++ b/hasura/migrations/1676470552127_alter_table_public_UserNotifications_drop_column_notification_id/up.sql @@ -0,0 +1 @@ +alter table "public"."UserNotifications" drop column "notification_id" cascade; diff --git a/src/components/organisms/AddSkilListSelector.tsx b/src/components/organisms/AddSkilListSelector.tsx index 128705ff..cef2b8d8 100644 --- a/src/components/organisms/AddSkilListSelector.tsx +++ b/src/components/organisms/AddSkilListSelector.tsx @@ -2,11 +2,11 @@ import { useMutation, useQuery } from "@apollo/client"; import { useContext, useState } from "react"; import { useMediaQuery } from "react-responsive"; import { - InsertSkillMutationMutation, SearchSkillsVerifiedQuery, Skill, + InsertSkillMutation, } from "../../generated/graphql"; -import { INSERT_SKILL_MUTATION } from "../../graphql/mutations/skills"; +import { INSERT_SKILL } from "../../graphql/mutations/skills"; import { displayNotification } from "../../utils/displayNotification"; import { i18nContext } from "../../utils/i18nContext"; import Button from "../atoms/Button"; @@ -17,6 +17,7 @@ import { getTutorialStep } from "../../constants/demo"; import { TutorialModeContext } from "../../utils/tutorialMode"; import { SEARCH_SKILLS_VERIFIED } from "../../graphql/queries/skills"; import { config } from "../../env"; +import { useAuth0 } from "@auth0/auth0-react"; import { useRouter } from "next/router"; const AddSkillListSelector = ({ @@ -41,6 +42,7 @@ const AddSkillListSelector = ({ const tutorialModeValue = useContext(TutorialModeContext); const { push } = useRouter(); const searchPageLink = `${config.nextPublicBaseUrl}/search`; + const { user } = useAuth0(); const closeModal = () => { setOpenSkillDetails(false); @@ -61,15 +63,15 @@ const AddSkillListSelector = ({ /* * MUTATIONS */ - const [insertSkill] = useMutation( - INSERT_SKILL_MUTATION - ); + const [insertSkill] = useMutation(INSERT_SKILL); const addSkillButtonClick = async () => { if (!categoryId || !search || search === "") { return; } - await insertSkill({ variables: { name: search, categoryId } }) + await insertSkill({ + variables: { name: search, categoryId, creator: user?.email }, + }) .then((response) => { if (!response.data.insert_Skill?.returning) { return; @@ -77,6 +79,7 @@ const AddSkillListSelector = ({ action(response.data.insert_Skill?.returning[0]); }) .catch(({ graphQLErrors }) => { + console.log("error", graphQLErrors); if (graphQLErrors) { displayNotification(`${t("error.insertSkillError")}`, "red", 5000); } else { diff --git a/src/components/organisms/EditSkillAdmin.tsx b/src/components/organisms/EditSkillAdmin.tsx index d21b5da1..ee63e861 100644 --- a/src/components/organisms/EditSkillAdmin.tsx +++ b/src/components/organisms/EditSkillAdmin.tsx @@ -27,6 +27,8 @@ import Loading from "../molecules/Loading"; import SkillDescription from "../molecules/SkillDescription"; import Topics from "../molecules/Topics"; import ErrorPage from "../templates/ErrorPage"; +import { INSERT_NOTIFICATION } from "../../graphql/mutations/notifications"; +import { useAuth0 } from "@auth0/auth0-react"; type EditSkillAdminProps = { skillId: string; @@ -35,7 +37,7 @@ type EditSkillAdminProps = { const EditSkillAdmin = ({ skillId }: EditSkillAdminProps) => { const { t } = useContext(i18nContext); const router = useRouter(); - + const { user } = useAuth0(); /* * QUERIES */ @@ -64,6 +66,10 @@ const EditSkillAdmin = ({ skillId }: EditSkillAdminProps) => { const [editSkill] = useMutation(EDIT_SKILL); const [insertTopic] = useMutation(ADD_SKILL_TO_TOPIC); const [deleteTopic] = useMutation(DELETE_SKILL_TO_TOPIC); + const [insertNotification] = useMutation(INSERT_NOTIFICATION); + const [updateVerifiedSkill] = useMutation( + UPDATE_SKILL_VERIFIED_MUTATION + ); const addTopic = (topic: TopicItem) => { insertTopic({ @@ -80,15 +86,20 @@ const EditSkillAdmin = ({ skillId }: EditSkillAdminProps) => { }); }; - const [updateVerifiedSkill] = useMutation( - UPDATE_SKILL_VERIFIED_MUTATION - ); - + //### MG_NOTIFICATIONS const updateVerifiedSkillButtonClick = async () => { updateVerifiedSkill({ variables: { skillId: skillId, verified: true }, }) .then(() => { + insertNotification({ + variables: { + userEmail: skillSelected?.Skill[0].creator, + skillId: skillId, + adminEmail: user?.Email, + checked: false, + }, + }); router.reload(); }) .catch(() => { diff --git a/src/graphql/mutations/notifications.ts b/src/graphql/mutations/notifications.ts new file mode 100644 index 00000000..ba6ea88c --- /dev/null +++ b/src/graphql/mutations/notifications.ts @@ -0,0 +1,21 @@ +import gql from "graphql-tag"; + +export const INSERT_NOTIFICATION = gql` + mutation insertNotification( + $userEmail: String! + $skillId: uuid! + $adminEmail: String! + $checked: Boolean! + ) { + insert_UserNotifications( + objects: { + user_email: $userEmail + skill_id: $skillId + admin_email: $adminEmail + checked: $checked + } + ) { + affected_rows + } + } +`; diff --git a/src/graphql/mutations/skills.ts b/src/graphql/mutations/skills.ts index 28f2b835..bdb8331b 100644 --- a/src/graphql/mutations/skills.ts +++ b/src/graphql/mutations/skills.ts @@ -24,12 +24,15 @@ export const ADD_USER_SKILL_MUTATION = gql` } `; -export const INSERT_SKILL_MUTATION = gql` - mutation insertSkillMutation($name: String!, $categoryId: uuid!) { - insert_Skill(objects: { name: $name, categoryId: $categoryId }) { +export const INSERT_SKILL = gql` + mutation insertSkill($name: String!, $categoryId: uuid!, $creator: String!) { + insert_Skill( + objects: { name: $name, categoryId: $categoryId, creator: $creator } + ) { returning { id name + creator } } } @@ -122,3 +125,14 @@ export const UPDATE_SKILL_DESCRIPTION = gql` } } `; + +export const UPDATE_SKILL_CREATOR = gql` + mutation updateSkillCreator($creator: String!, $skillId: uuid!) { + update_Skill( + where: { id: { _eq: $skillId } } + _set: { creator: $creator } + ) { + affected_rows + } + } +`; diff --git a/src/graphql/queries/notifications.ts b/src/graphql/queries/notifications.ts new file mode 100644 index 00000000..44490b3b --- /dev/null +++ b/src/graphql/queries/notifications.ts @@ -0,0 +1,17 @@ +import gql from "graphql-tag"; + +export const GET_NOTIFICATIONS = gql` + query getNotifications($userEmail: String!) { + UserNotifications(where: { user_email: { _eq: $userEmail } }) { + admin_email + checked + created_at + skill { + name + Category { + label + } + } + } + } +`; diff --git a/src/graphql/queries/skills.ts b/src/graphql/queries/skills.ts index f4bb1c5e..df9a2b77 100644 --- a/src/graphql/queries/skills.ts +++ b/src/graphql/queries/skills.ts @@ -324,6 +324,7 @@ export const GET_SKILL_MANDATORY_FIELDS = gql` topicId skillId } + creator description name categoryId From 3b385db1d2eca8a300d39ac87734b3027527f85f Mon Sep 17 00:00:00 2001 From: Mai-ly Date: Tue, 21 Feb 2023 09:43:01 +0100 Subject: [PATCH 3/5] :recycle: add permissions and fix some nullable values --- hasura/metadata/tables.yaml | 20 ++++++++++ i18n/en.js | 1 + i18n/fr.js | 1 + src/components/organisms/EditSkillAdmin.tsx | 2 +- src/components/organisms/Profile.tsx | 2 +- src/components/organisms/TopBar.tsx | 22 +++++++++-- src/components/templates/AdminPage.tsx | 2 +- src/pages/admin/skills.tsx | 4 +- src/pages/notifications.tsx | 43 +++++++++++++++++++++ 9 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/pages/notifications.tsx diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index bbd2a3da..c323d410 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -527,6 +527,26 @@ remote_table: name: Skill schema: public + insert_permissions: + - role: world + permission: + check: {} + columns: + - admin_email + - checked + - created_at + - skill_id + - user_email + select_permissions: + - role: world + permission: + columns: + - admin_email + - checked + - created_at + - skill_id + - user_email + filter: {} - table: name: UserSkillDesire schema: public diff --git a/i18n/en.js b/i18n/en.js index ef6cc13e..4aedeb3a 100644 --- a/i18n/en.js +++ b/i18n/en.js @@ -51,6 +51,7 @@ export default { profile: "Profile", language: "Language", darkMode: "Dark mode", + notifications: "Notifications", logout: "Logout", tutorial: "Tutorial mode", botNotifications: "Slack bot notifications", diff --git a/i18n/fr.js b/i18n/fr.js index 4fe29b0c..09219bb9 100644 --- a/i18n/fr.js +++ b/i18n/fr.js @@ -50,6 +50,7 @@ export default { profile: "Profil", language: "Langue", darkMode: "Mode sombre", + notifications: "Notifications", logout: "Se déconnecter", tutorial: "Mode tutoriel", botNotifications: "Notifications du bot Slack", diff --git a/src/components/organisms/EditSkillAdmin.tsx b/src/components/organisms/EditSkillAdmin.tsx index ee63e861..c4bb4a74 100644 --- a/src/components/organisms/EditSkillAdmin.tsx +++ b/src/components/organisms/EditSkillAdmin.tsx @@ -96,7 +96,7 @@ const EditSkillAdmin = ({ skillId }: EditSkillAdminProps) => { variables: { userEmail: skillSelected?.Skill[0].creator, skillId: skillId, - adminEmail: user?.Email, + adminEmail: user?.email, checked: false, }, }); diff --git a/src/components/organisms/Profile.tsx b/src/components/organisms/Profile.tsx index 45231766..91856f6d 100644 --- a/src/components/organisms/Profile.tsx +++ b/src/components/organisms/Profile.tsx @@ -183,7 +183,7 @@ const Profile = ({ return ; } else { return ( - +
{/* ONBOARDING */} diff --git a/src/components/organisms/TopBar.tsx b/src/components/organisms/TopBar.tsx index a37788ca..1f05c311 100644 --- a/src/components/organisms/TopBar.tsx +++ b/src/components/organisms/TopBar.tsx @@ -49,14 +49,14 @@ const TopBar = ({ togglePanel }: TopBarProps) => { const { data: userAgencyResult } = useQuery( GET_USER_AGENCY_QUERY, { - variables: { email: user.email }, + variables: { email: user?.email }, fetchPolicy: "network-only", } ); const { data: userSkills } = useQuery( GET_USER_SKILLS_ID, { - variables: { email: user.email, fetchPolicy: "network-only" }, + variables: { email: user?.email, fetchPolicy: "network-only" }, } ); @@ -291,7 +291,7 @@ const TopBar = ({ togglePanel }: TopBarProps) => {
  • {

    {t("sidepanel.profile")}

  • + {/*Separator*/} +
  • + + {"Notifications"} +

    {t("sidepanel.notifications")}

    + +
  • + {/*Separator*/}
  • admin === user.email) + !config.nextPublicAdmins.split(";").find((admin) => admin === user?.email) ) { push("/"); return ; diff --git a/src/pages/admin/skills.tsx b/src/pages/admin/skills.tsx index 40fef00a..20a7d053 100644 --- a/src/pages/admin/skills.tsx +++ b/src/pages/admin/skills.tsx @@ -67,7 +67,7 @@ export default function AdminSkillsPage() {

    {t("admin.skillsPending")}

    - {skills.Skill && ( + {skills?.Skill && (

    { skills.Skill.filter((field) => field.verified === false) @@ -77,7 +77,7 @@ export default function AdminSkillsPage() {

    )}
    - {skills.Skill.length > 0 && + {skills?.Skill.length > 0 && skills.Skill.filter((field) => field.verified == false).map( (skill, index) => ( { + /* + * STATES + */ + const { user } = useAuth0(); + /* + * QUERIES + */ + const { data: notifications, error } = useQuery( + GET_NOTIFICATIONS, + { + variables: { + userEmail: user?.email, + }, + fetchPolicy: "network-only", + } + ); + + if (error) console.log("error", error); + useEffect(() => { + if (notifications) console.log("notif", notifications); + }, [notifications]); + return ( + +
    + {notifications?.UserNotifications.length > 0 && + notifications.UserNotifications.map((notification) => ( + {notification.skill.name} + ))} +
    +
    + ); +}; + +export default Notifications; From 2d044bc9f7133e1881889ab784d65defc39ce5eb Mon Sep 17 00:00:00 2001 From: Mai-ly Date: Wed, 22 Feb 2023 16:31:21 +0100 Subject: [PATCH 4/5] :lipstick: add checked ui/ux --- README.md | 40 +++++------ hasura/metadata/tables.yaml | 12 +++- i18n/en.js | 6 ++ i18n/fr.js | 6 ++ .../organisms/NotificationPanel.tsx | 66 +++++++++++++++++++ src/graphql/mutations/notifications.ts | 11 ++++ src/graphql/queries/notifications.ts | 2 + src/pages/admin/skills.tsx | 4 +- src/pages/notifications.tsx | 8 +-- src/utils/types.ts | 16 +++-- 10 files changed, 137 insertions(+), 34 deletions(-) create mode 100644 src/components/organisms/NotificationPanel.tsx diff --git a/README.md b/README.md index 4ec53487..d83634f6 100644 --- a/README.md +++ b/README.md @@ -16,28 +16,28 @@ questions on the channel #project-skillz in the Zenika's Slack. # Table of contents 1. [Skillz web app](#skillzwebapp) - 1. [Requirements](#requirements) - 2. [Quick Start](#quickstart) - 1. [Docker](#docker) - 2. [Install dependencies](#dependencies) - 3. [Create an .env file](#.env) - 4. [Run postgres and hasura locally with docker](#postgres) - 5. [Run the hasura migrations](#hasuramigrations) - 6. [Develop with hasura](#devhasura) - 7. [Launch the app](#launch) - 8. [Generate local seeds](#localseeds) - 3. [Tests](#tests) - 1. [E2E with Cypress](#e2e) - 2. [Management rules](#managementrules) + 1. [Requirements](#requirements) + 2. [Quick Start](#quickstart) + 1. [Docker](#docker) + 2. [Install dependencies](#dependencies) + 3. [Create an .env file](#.env) + 4. [Run postgres and hasura locally with docker](#postgres) + 5. [Run the hasura migrations](#hasuramigrations) + 6. [Develop with hasura](#devhasura) + 7. [Launch the app](#launch) + 8. [Generate local seeds](#localseeds) + 3. [Tests](#tests) + 1. [E2E with Cypress](#e2e) + 2. [Management rules](#managementrules) 2. [Skillz Slack bot](#slackbot) - 1. [Documentation](#documentation) - 2. [Development](#development) - 1. [Configuration](#configuration) - 2. [Versionning](#versionning) + 1. [Documentation](#documentation) + 2. [Development](#development) + 1. [Configuration](#configuration) + 2. [Versionning](#versionning) 3. [Github](#github) - 1. [Actions](#actions) - 1. [Update referentials](#update-referentials) - 2. [Dependabot](#dependabot) + 1. [Actions](#actions) + 1. [Update referentials](#update-referentials) + 2. [Dependabot](#dependabot) # Skillz web app diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index c323d410..9d253725 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -544,9 +544,17 @@ - admin_email - checked - created_at + - id - skill_id - user_email filter: {} + update_permissions: + - role: world + permission: + columns: + - checked + filter: {} + check: null - table: name: UserSkillDesire schema: public @@ -607,7 +615,7 @@ definition: enable_manual: false insert: - columns: '*' + columns: "*" retry_conf: interval_sec: 30 num_retries: 5 @@ -669,7 +677,7 @@ definition: enable_manual: false insert: - columns: '*' + columns: "*" retry_conf: interval_sec: 30 num_retries: 5 diff --git a/i18n/en.js b/i18n/en.js index 4aedeb3a..bc96ad01 100644 --- a/i18n/en.js +++ b/i18n/en.js @@ -124,6 +124,12 @@ export default { }, }, }, + notification: { + notificationText: + "Admin adminMail has approved your skill skillName as new Skillz's skills.", + new: "New", + notificationTypeAccepted: "One of your skill has been accepted", + }, loading: { loadingText: "Loading...", }, diff --git a/i18n/fr.js b/i18n/fr.js index 09219bb9..d4cb6377 100644 --- a/i18n/fr.js +++ b/i18n/fr.js @@ -123,6 +123,12 @@ export default { }, }, }, + notification: { + notificationText: + "L'administrateur adminMail a approuvé votre compétence skillName comme nouvelle compétence Skillz", + new: "Nouveau", + notificationTypeAccepted: "Une de tes compétence a été acceptée", + }, loading: { loadingText: "Chargement...", }, diff --git a/src/components/organisms/NotificationPanel.tsx b/src/components/organisms/NotificationPanel.tsx new file mode 100644 index 00000000..366d2c3b --- /dev/null +++ b/src/components/organisms/NotificationPanel.tsx @@ -0,0 +1,66 @@ +import { useEffect } from "react"; +import { useContext } from "react"; +import { i18nContext } from "../../utils/i18nContext"; +import { Notifications } from "../../utils/types"; +import { useMutation } from "@apollo/client"; +import { UPDATE_NOTIFICATION_CHECK } from "../../graphql/mutations/notifications"; +// import { } from "../../generated/graphql"; + +const NotificationsPanel = ({ + notification, +}: { + notification: Notifications; +}) => { + /* + * STATES + */ + const { t } = useContext(i18nContext); + const notificationTrad = { + adminMail: notification.admin_email, + skillName: notification.skill?.name, + }; + + /* + * MUTATIONS + */ + const [updateNotificationCheck] = useMutation(UPDATE_NOTIFICATION_CHECK, { + variables: { + id: notification.id, + }, + }); + console.log("coucou"); + + useEffect(() => { + updateNotificationCheck(); + }, []); + + return ( +
    + {notification.checked === false && ( +
    + {t("notification.new")} +
    + )} +
    +

    + {t("notification.notificationTypeAccepted")} +

    + +
    +

    + {t("notification.notificationText").replace( + /adminMail|skillName/gi, + (matched) => notificationTrad[matched] + )} +

    +
    + +

    {notification.created_at}

    +
    +
    + ); +}; + +export default NotificationsPanel; diff --git a/src/graphql/mutations/notifications.ts b/src/graphql/mutations/notifications.ts index ba6ea88c..0a9e0ca5 100644 --- a/src/graphql/mutations/notifications.ts +++ b/src/graphql/mutations/notifications.ts @@ -19,3 +19,14 @@ export const INSERT_NOTIFICATION = gql` } } `; + +export const UPDATE_NOTIFICATION_CHECK = gql` + mutation updateNotificationCheck($id: uuid) { + update_UserNotifications( + where: { id: { _eq: $id } } + _set: { checked: true } + ) { + affected_rows + } + } +`; diff --git a/src/graphql/queries/notifications.ts b/src/graphql/queries/notifications.ts index 44490b3b..794a3d03 100644 --- a/src/graphql/queries/notifications.ts +++ b/src/graphql/queries/notifications.ts @@ -4,11 +4,13 @@ export const GET_NOTIFICATIONS = gql` query getNotifications($userEmail: String!) { UserNotifications(where: { user_email: { _eq: $userEmail } }) { admin_email + id checked created_at skill { name Category { + id label } } diff --git a/src/pages/admin/skills.tsx b/src/pages/admin/skills.tsx index 20a7d053..d7da3bfe 100644 --- a/src/pages/admin/skills.tsx +++ b/src/pages/admin/skills.tsx @@ -63,7 +63,7 @@ export default function AdminSkillsPage() { setSearch={setSearch} placeholder={t("search.placeholder")} /> - {!loading && ( + {!loading && skills && skills.Skill && (

    {t("admin.skillsPending")}

    @@ -77,7 +77,7 @@ export default function AdminSkillsPage() {

    )}
    - {skills?.Skill.length > 0 && + {skills.Skill.length > 0 && skills.Skill.filter((field) => field.verified == false).map( (skill, index) => ( { /* @@ -24,16 +24,12 @@ const Notifications = ({}) => { } ); - if (error) console.log("error", error); - useEffect(() => { - if (notifications) console.log("notif", notifications); - }, [notifications]); return (
    {notifications?.UserNotifications.length > 0 && notifications.UserNotifications.map((notification) => ( - {notification.skill.name} + ))}
    diff --git a/src/utils/types.ts b/src/utils/types.ts index b89461a1..7c444eff 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -56,10 +56,10 @@ export type TopicItem = { export type CategoryItem = { id: string; label: string; - color: string; - x: string; - y: string; - index: number; + color?: string | null | undefined; + x?: string | null | undefined; + y?: string | null | undefined; + index?: number | null | undefined; description?: string | null; }; @@ -83,3 +83,11 @@ export type Skill = { UserSkillDesires?: any | null; Category?: CategoryItem | null; }; + +export type Notifications = { + admin_email: string; + id: string; + checked: boolean; + created_at: string; + skill?: Skill | null | undefined; +}; From 362f4b20dc30d94043fb05f3311538d4bc75871c Mon Sep 17 00:00:00 2001 From: Mai-ly Date: Mon, 27 Feb 2023 11:40:03 +0100 Subject: [PATCH 5/5] :lipstick: add notification bullet in profile and side menu --- .../organisms/AddSkilListSelector.tsx | 1 - .../organisms/NotificationPanel.tsx | 7 ++-- src/components/organisms/TopBar.tsx | 42 +++++++++++++++---- src/graphql/queries/notifications.ts | 10 +++++ src/pages/notifications.tsx | 6 +-- 5 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/components/organisms/AddSkilListSelector.tsx b/src/components/organisms/AddSkilListSelector.tsx index cef2b8d8..a068ff78 100644 --- a/src/components/organisms/AddSkilListSelector.tsx +++ b/src/components/organisms/AddSkilListSelector.tsx @@ -79,7 +79,6 @@ const AddSkillListSelector = ({ action(response.data.insert_Skill?.returning[0]); }) .catch(({ graphQLErrors }) => { - console.log("error", graphQLErrors); if (graphQLErrors) { displayNotification(`${t("error.insertSkillError")}`, "red", 5000); } else { diff --git a/src/components/organisms/NotificationPanel.tsx b/src/components/organisms/NotificationPanel.tsx index 366d2c3b..9fd62bfb 100644 --- a/src/components/organisms/NotificationPanel.tsx +++ b/src/components/organisms/NotificationPanel.tsx @@ -4,12 +4,13 @@ import { i18nContext } from "../../utils/i18nContext"; import { Notifications } from "../../utils/types"; import { useMutation } from "@apollo/client"; import { UPDATE_NOTIFICATION_CHECK } from "../../graphql/mutations/notifications"; -// import { } from "../../generated/graphql"; const NotificationsPanel = ({ notification, + key, }: { notification: Notifications; + key: number; }) => { /* * STATES @@ -28,15 +29,15 @@ const NotificationsPanel = ({ id: notification.id, }, }); - console.log("coucou"); useEffect(() => { updateNotificationCheck(); - }, []); + }, [updateNotificationCheck]); return (
    {notification.checked === false && (
    diff --git a/src/components/organisms/TopBar.tsx b/src/components/organisms/TopBar.tsx index 1f05c311..287d2916 100644 --- a/src/components/organisms/TopBar.tsx +++ b/src/components/organisms/TopBar.tsx @@ -10,6 +10,7 @@ import { GetAllNotVerifiedSkillsQuery, GetUserAgencyQuery, GetUserQuery, + GetUnreadNotificationsQuery, } from "../../generated/graphql"; import { GET_ALL_NOT_VERIFIED_SKILL } from "../../graphql/queries/skills"; import { @@ -25,6 +26,8 @@ import { TutorialMode } from "../molecules/TutorialMode"; import { useTutorialMode } from "../../utils/tutorialMode"; import { GET_USER_SKILLS_ID } from "../../graphql/queries/skills"; import { GetUserSkillsIdQuery } from "../../generated/graphql"; +import { GET_UNREAD_NOTIFICATIONS } from "../../graphql/queries/notifications"; +import { MdNotifications } from "react-icons/md"; export type TopBarProps = { togglePanel: () => void; @@ -53,6 +56,13 @@ const TopBar = ({ togglePanel }: TopBarProps) => { fetchPolicy: "network-only", } ); + const { data: unreadNotifications } = useQuery( + GET_UNREAD_NOTIFICATIONS, + { + variables: { userEmail: user?.email }, + fetchPolicy: "network-only", + } + ); const { data: userSkills } = useQuery( GET_USER_SKILLS_ID, { @@ -275,6 +285,7 @@ const TopBar = ({ togglePanel }: TopBarProps) => { )}`}

    )}
    + {user?.name} { height="64" width="64" /> + {unreadNotifications?.UserNotifications.length > 0 && ( +
    + {unreadNotifications?.UserNotifications.length} +
    + )} +
    {
  • {/*Separator*/} -
  • +
  • - {"Notifications"} +
    + {unreadNotifications?.UserNotifications.length > 0 ? ( +
    + {unreadNotifications?.UserNotifications.length} +
    + ) : ( + + )} +

    {t("sidepanel.notifications")}

  • diff --git a/src/graphql/queries/notifications.ts b/src/graphql/queries/notifications.ts index b308eee1..ac527f59 100644 --- a/src/graphql/queries/notifications.ts +++ b/src/graphql/queries/notifications.ts @@ -20,3 +20,13 @@ export const GET_NOTIFICATIONS = gql` } } `; + +export const GET_UNREAD_NOTIFICATIONS = gql` + query getUnreadNotifications($userEmail: String!) { + UserNotifications( + where: { user_email: { _eq: $userEmail }, checked: { _eq: false } } + ) { + id + } + } +`; diff --git a/src/pages/notifications.tsx b/src/pages/notifications.tsx index c038f703..b7eda6c5 100644 --- a/src/pages/notifications.tsx +++ b/src/pages/notifications.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useState } from "react"; +import React from "react"; import CommonPage from "../components/templates/CommonPage"; import { GET_NOTIFICATIONS } from "../graphql/queries/notifications"; import { GetNotificationsQuery } from "../generated/graphql"; @@ -28,8 +28,8 @@ const Notifications = ({}) => {
    {notifications?.UserNotifications.length > 0 && - notifications.UserNotifications.map((notification) => ( - + notifications.UserNotifications.map((notification, key) => ( + ))}