diff --git a/docker-compose.yaml b/docker-compose.yaml index 5d4c56db0d..9dd01c2abd 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,3 @@ -version: '3' services: postgresql: image: postgres:17.2 diff --git a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfile.java b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfile.java index e1fc5efdbf..51a92cd0a6 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfile.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfile.java @@ -155,6 +155,11 @@ public class MemberProfile { @TypeDef(type = DataType.DATE, converter = LocalDateConverter.class) private LocalDate lastSeen; + @Column(name="ignore_birthday") + @Schema(description = "flag indicating the member would like to have their birthday ignored") + @Nullable + private Boolean ignoreBirthday; + public MemberProfile(@NotBlank String firstName, @Nullable String middleName, @NotBlank String lastName, @@ -171,9 +176,10 @@ public MemberProfile(@NotBlank String firstName, @Nullable LocalDate birthDate, @Nullable Boolean voluntary, @Nullable Boolean excluded, - @Nullable LocalDate lastSeen) { + @Nullable LocalDate lastSeen, + @Nullable Boolean ignoreBirthday) { this(null, firstName, middleName, lastName, suffix, title, pdlId, location, workEmail, - employeeId, startDate, bioText, supervisorid, terminationDate,birthDate, voluntary, excluded, lastSeen); + employeeId, startDate, bioText, supervisorid, terminationDate,birthDate, voluntary, excluded, lastSeen, ignoreBirthday); } public MemberProfile(UUID id, @@ -193,7 +199,8 @@ public MemberProfile(UUID id, @Nullable LocalDate birthDate, @Nullable Boolean voluntary, @Nullable Boolean excluded, - @Nullable LocalDate lastSeen) { + @Nullable LocalDate lastSeen, + @Nullable Boolean ignoreBirthday) { this.id = id; this.firstName = firstName; this.middleName = middleName; @@ -212,6 +219,7 @@ public MemberProfile(UUID id, this.voluntary = voluntary; this.excluded = excluded; this.lastSeen = lastSeen; + this.ignoreBirthday = ignoreBirthday; } public MemberProfile() { @@ -246,14 +254,15 @@ public boolean equals(Object o) { Objects.equals(birthDate, that.birthDate) && Objects.equals(voluntary, that.voluntary) && Objects.equals(excluded, that.excluded) && - Objects.equals(lastSeen, that.lastSeen); + Objects.equals(lastSeen, that.lastSeen) && + Objects.equals(ignoreBirthday, that.ignoreBirthday); } @Override public int hashCode() { return Objects.hash(id, firstName, middleName, lastName, suffix, title, pdlId, location, workEmail, employeeId, startDate, bioText, supervisorid, terminationDate,birthDate, - voluntary, excluded, lastSeen); + voluntary, excluded, lastSeen, ignoreBirthday); } @Override @@ -274,6 +283,7 @@ public String toString() { ", voluntary=" + voluntary + ", excluded=" + excluded + ", lastSeen=" + lastSeen + + ", ignoreBirthday=" + ignoreBirthday + '}'; } } diff --git a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileController.java b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileController.java index c79727b6ba..dab6c285a0 100755 --- a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileController.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileController.java @@ -58,7 +58,7 @@ public HttpResponse getById(UUID id) { public List getSupervisorsForId(UUID id) { return memberProfileServices.getSupervisorsForId(id) .stream() - .map(this::fromEntity) + .map(MemberProfileController::fromEntity) .toList(); } @@ -83,7 +83,7 @@ public List findByValue(@Nullable String firstName, @QueryValue(value = "terminated", defaultValue = "false") Boolean terminated) { return memberProfileServices.findByValues(firstName, lastName, title, pdlId, workEmail, supervisorId, terminated) .stream() - .map(this::fromEntity) + .map(MemberProfileController::fromEntity) .toList(); } @@ -128,7 +128,7 @@ protected URI location(UUID id) { return URI.create("/member-profiles/" + id); } - private MemberProfileResponseDTO fromEntity(MemberProfile entity) { + public static MemberProfileResponseDTO fromEntity(MemberProfile entity) { MemberProfileResponseDTO dto = new MemberProfileResponseDTO(); dto.setId(entity.getId()); dto.setFirstName(entity.getFirstName()); @@ -147,6 +147,7 @@ private MemberProfileResponseDTO fromEntity(MemberProfile entity) { dto.setTerminationDate(entity.getTerminationDate()); dto.setBirthDay(entity.getBirthDate()); dto.setLastSeen(entity.getLastSeen()); + dto.setIgnoreBirthday(entity.getIgnoreBirthday()); return dto; } @@ -154,13 +155,13 @@ private MemberProfile fromDTO(MemberProfileUpdateDTO dto) { return new MemberProfile(dto.getId(), dto.getFirstName(), dto.getMiddleName(), dto.getLastName(), dto.getSuffix(), dto.getTitle(), dto.getPdlId(), dto.getLocation(), dto.getWorkEmail(), dto.getEmployeeId(), dto.getStartDate(), dto.getBioText(), dto.getSupervisorid(), - dto.getTerminationDate(), dto.getBirthDay(), dto.getVoluntary(), dto.getExcluded(), dto.getLastSeen()); + dto.getTerminationDate(), dto.getBirthDay(), dto.getVoluntary(), dto.getExcluded(), dto.getLastSeen(), dto.getIgnoreBirthday()); } private MemberProfile fromDTO(MemberProfileCreateDTO dto) { return new MemberProfile(dto.getFirstName(), dto.getMiddleName(), dto.getLastName(), dto.getSuffix(), dto.getTitle(), dto.getPdlId(), dto.getLocation(), dto.getWorkEmail(), dto.getEmployeeId(), dto.getStartDate(), dto.getBioText(), dto.getSupervisorid(), dto.getTerminationDate(), dto.getBirthDay(), - dto.getVoluntary(), dto.getExcluded(), dto.getLastSeen()); + dto.getVoluntary(), dto.getExcluded(), dto.getLastSeen(), dto.getIgnoreBirthday()); } } diff --git a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileCreateDTO.java b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileCreateDTO.java index 4cc079033f..8c59002210 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileCreateDTO.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileCreateDTO.java @@ -85,6 +85,10 @@ public class MemberProfileCreateDTO { @Schema(description = "Last date employee logged in") private LocalDate lastSeen; + @Nullable + @Schema(description = "The employee would like their birthday to not be celebrated", nullable = true) + private Boolean ignoreBirthday; + @Override public boolean equals(Object o) { if (this == o) return true; @@ -106,7 +110,8 @@ public boolean equals(Object o) { Objects.equals(birthDay, that.birthDay) && Objects.equals(voluntary, that.voluntary) && Objects.equals(excluded, that.excluded) && - Objects.equals(lastSeen, that.lastSeen); + Objects.equals(lastSeen, that.lastSeen) && + Objects.equals(ignoreBirthday, that.ignoreBirthday); } @@ -114,6 +119,6 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(firstName, middleName, lastName, suffix, title, pdlId, location, workEmail, employeeId, startDate, bioText, supervisorid, terminationDate, birthDay, - voluntary, excluded, lastSeen); + voluntary, excluded, lastSeen, ignoreBirthday); } } diff --git a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileRepository.java b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileRepository.java index f9f448d29f..8d0420f23d 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileRepository.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileRepository.java @@ -27,7 +27,7 @@ public interface MemberProfileRepository extends CrudRepository findWorkEmailByIdIn(Set ids); @Query(value = "WITH RECURSIVE subordinate AS (SELECT " + - "id, firstname, middlename, lastname, suffix, title, pdlid, location, workemail, employeeid, startdate, biotext, supervisorid, terminationdate, birthdate, voluntary, excluded, last_seen, 0 as level " + + "id, firstname, middlename, lastname, suffix, title, pdlid, location, workemail, employeeid, startdate, biotext, supervisorid, terminationdate, birthdate, voluntary, excluded, last_seen, ignore_birthday, 0 as level " + "FROM member_profile " + "WHERE id = :id and terminationdate is NULL " + " UNION ALL " + "SELECT " + - "e.id, e.firstname, e.middlename, e.lastname, e.suffix, e.title, e.pdlid, e.location, e.workemail, e.employeeid, e.startdate, e.biotext, e.supervisorid, e.terminationdate, e.birthdate, e.voluntary, e.excluded, e.last_seen, level + 1 " + + "e.id, e.firstname, e.middlename, e.lastname, e.suffix, e.title, e.pdlid, e.location, e.workemail, e.employeeid, e.startdate, e.biotext, e.supervisorid, e.terminationdate, e.birthdate, e.voluntary, e.excluded, e.last_seen, e.ignore_birthday, level + 1 " + "FROM member_profile e " + "JOIN subordinate s " + "ON s.supervisorid = e.id " + @@ -96,7 +96,7 @@ WHERE mp.id IN (:ids)""", "PGP_SYM_DECRYPT(cast(s.workemail as bytea), '${aes.key}') as workemail, " + "s.employeeid, s.startdate, " + "PGP_SYM_DECRYPT(cast(s.biotext as bytea), '${aes.key}') as biotext, " + - "s.supervisorid, s.terminationdate, s.birthdate, s.voluntary, s.excluded, s.last_seen, " + + "s.supervisorid, s.terminationdate, s.birthdate, s.voluntary, s.excluded, s.last_seen, s.ignore_birthday, " + "s.level " + "FROM subordinate s " + "WHERE s.id <> :id " + @@ -106,11 +106,11 @@ WHERE mp.id IN (:ids)""", @Query( value = """ WITH RECURSIVE subordinate AS ( - SELECT id, firstname, middlename, lastname, suffix, title, pdlid, location, workemail, employeeid, startdate, biotext, supervisorid, terminationdate, birthdate, voluntary, excluded, last_seen, 0 as level + SELECT id, firstname, middlename, lastname, suffix, title, pdlid, location, workemail, employeeid, startdate, biotext, supervisorid, terminationdate, birthdate, voluntary, excluded, last_seen, ignore_birthday, 0 as level FROM member_profile WHERE id = :id and terminationdate is NULL UNION ALL - SELECT e.id, e.firstname, e.middlename, e.lastname, e.suffix, e.title, e.pdlid, e.location, e.workemail, e.employeeid, e.startdate, e.biotext, e.supervisorid, e.terminationdate, e.birthdate, e.voluntary, e.excluded, e.last_seen, level + 1 + SELECT e.id, e.firstname, e.middlename, e.lastname, e.suffix, e.title, e.pdlid, e.location, e.workemail, e.employeeid, e.startdate, e.biotext, e.supervisorid, e.terminationdate, e.birthdate, e.voluntary, e.excluded, e.last_seen, e.ignore_birthday, level + 1 FROM member_profile AS e JOIN subordinate AS s ON s.id = e.supervisorid WHERE e.terminationdate is NULL ) @@ -126,7 +126,7 @@ WITH RECURSIVE subordinate AS ( PGP_SYM_DECRYPT(cast(s.workemail as bytea), '${aes.key}') as workemail, s.employeeid, s.startdate, PGP_SYM_DECRYPT(cast(s.biotext as bytea), '${aes.key}') as biotext, - s.supervisorid, s.terminationdate, s.birthdate, s.voluntary, s.excluded, s.last_seen, + s.supervisorid, s.terminationdate, s.birthdate, s.voluntary, s.excluded, s.last_seen, s.ignore_birthday, s.level FROM subordinate s WHERE s.id <> :id diff --git a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileResponseDTO.java b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileResponseDTO.java index 40fe0bd670..36a6570740 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileResponseDTO.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileResponseDTO.java @@ -92,6 +92,10 @@ public class MemberProfileResponseDTO { @Schema(description = "Last date employee logged in") private LocalDate lastSeen; + @Nullable + @Schema(description = "The employee would like their birthday to not be celebrated", nullable = true) + private Boolean ignoreBirthday; + @Override public String toString() { return "MemberProfileResponseDTO{" + @@ -114,6 +118,7 @@ public String toString() { ", voluntary=" + voluntary + ", excluded=" + excluded + ", lastSeen=" + lastSeen + + ", ignoreBirthday=" + ignoreBirthday + '}'; } } diff --git a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileUpdateDTO.java b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileUpdateDTO.java index 4f17f003b6..95d74e45ce 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileUpdateDTO.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileUpdateDTO.java @@ -87,4 +87,8 @@ public class MemberProfileUpdateDTO { @Nullable @Schema(description = "Last date employee logged in", nullable = true) private LocalDate lastSeen; + + @Nullable + @Schema(description = "The employee would like their birthday to not be celebrated", nullable = true) + private Boolean ignoreBirthday; } diff --git a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/birthday/BirthDayServicesImpl.java b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/birthday/BirthDayServicesImpl.java index 015bb88559..a71f7c9cf4 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/birthday/BirthDayServicesImpl.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/birthday/BirthDayServicesImpl.java @@ -38,7 +38,7 @@ public List findByValue(String[] months, Integer[] daysOfMo if (month != null) { memberProfileAll = memberProfileAll .stream() - .filter(member -> member.getBirthDate() != null && month.equalsIgnoreCase(member.getBirthDate().getMonth().name()) && member.getTerminationDate() == null) + .filter(member -> member.getBirthDate() != null && month.equalsIgnoreCase(member.getBirthDate().getMonth().name()) && member.getTerminationDate() == null && (member.getIgnoreBirthday() == null || member.getIgnoreBirthday() == Boolean.FALSE)) .toList(); } } @@ -48,7 +48,7 @@ public List findByValue(String[] months, Integer[] daysOfMo if (day != null) { memberProfileAll = memberProfiles .stream() - .filter(member -> member.getBirthDate() != null && day.equals(member.getBirthDate().getDayOfMonth()) && member.getTerminationDate() == null) + .filter(member -> member.getBirthDate() != null && day.equals(member.getBirthDate().getDayOfMonth()) && member.getTerminationDate() == null && (member.getIgnoreBirthday() == null || member.getIgnoreBirthday() == Boolean.FALSE)) .toList(); } } @@ -63,7 +63,7 @@ public List getTodaysBirthdays() { LocalDate today = LocalDate.now(); List results = memberProfiles .stream() - .filter(member -> member.getBirthDate() != null && today.getMonthValue() == member.getBirthDate().getMonthValue()) + .filter(member -> member.getBirthDate() != null && today.getMonthValue() == member.getBirthDate().getMonthValue() && (member.getIgnoreBirthday() == null || member.getIgnoreBirthday() == Boolean.FALSE)) .toList(); return profileToBirthDateResponseDto(results); } diff --git a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/currentuser/CurrentUserController.java b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/currentuser/CurrentUserController.java index 68d185b64f..49ce695718 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/currentuser/CurrentUserController.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/memberprofile/currentuser/CurrentUserController.java @@ -1,6 +1,7 @@ package com.objectcomputing.checkins.services.memberprofile.currentuser; import com.objectcomputing.checkins.services.memberprofile.MemberProfile; +import com.objectcomputing.checkins.services.memberprofile.MemberProfileController; import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices; import com.objectcomputing.checkins.services.memberprofile.MemberProfileUtils; import com.objectcomputing.checkins.services.permissions.Permission; @@ -86,7 +87,7 @@ private CurrentUserDTO fromEntity(MemberProfile entity, String imageUrl, List role = roleServices.findByRole("MEMBER"); if(role.isPresent()){ diff --git a/server/src/main/resources/db/common/V122__add_disable_bday_flag.sql b/server/src/main/resources/db/common/V122__add_disable_bday_flag.sql new file mode 100644 index 0000000000..0bb0927759 --- /dev/null +++ b/server/src/main/resources/db/common/V122__add_disable_bday_flag.sql @@ -0,0 +1 @@ +ALTER TABLE member_profile ADD column ignore_birthday boolean; diff --git a/server/src/test/java/com/objectcomputing/checkins/services/fixture/FeedbackRequestFixture.java b/server/src/test/java/com/objectcomputing/checkins/services/fixture/FeedbackRequestFixture.java index 29c427f94d..9ccf960943 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/fixture/FeedbackRequestFixture.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/fixture/FeedbackRequestFixture.java @@ -103,7 +103,7 @@ default MemberProfile createADefaultRecipient() { null, "Parks Director", null, "Pawnee, Indiana", "ron@objectcomputing.com", "mr-ron-swanson", LocalDate.now(), "enjoys woodworking, breakfast meats, and saxophone jazz", - null, null, null, false, false, null)); + null, null, null, false, false, null, false)); } default MemberProfile createASecondDefaultRecipient() { @@ -111,7 +111,7 @@ default MemberProfile createASecondDefaultRecipient() { null, "Parks Deputy Director", null, "Pawnee, Indiana", "leslie@objectcomputing.com", "ms-leslie-knope", LocalDate.now(), "proud member of numerous action committees", - null, null, null, false, false, null)); + null, null, null, false, false, null, false)); } default FeedbackRequest createFeedbackRequest(MemberProfile creator, MemberProfile requestee, MemberProfile recipient) { diff --git a/server/src/test/java/com/objectcomputing/checkins/services/fixture/MemberProfileFixture.java b/server/src/test/java/com/objectcomputing/checkins/services/fixture/MemberProfileFixture.java index b45f82ebfa..20258206f1 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/fixture/MemberProfileFixture.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/fixture/MemberProfileFixture.java @@ -12,7 +12,7 @@ default MemberProfile createADefaultMemberProfile() { null, "Comedic Relief", null, "New York, New York", "billm@objectcomputing.com", "mr-bill-employee", LocalDate.now().minusDays(3).minusYears(5), "is a clay figurine clown star of a parody of children's clay animation shows", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createADefaultMemberProfileWithBirthDayToday() { @@ -21,7 +21,7 @@ default MemberProfile createADefaultMemberProfileWithBirthDayToday() { null, "Comedic Relief", null, "New York, New York", "billm@objectcomputing.com", "mr-billy-employee-today", LocalDate.now().minusDays(3).minusMonths(1).minusYears(5), "is a clay figurine clown star of a parody of children's clay animation shows", - null, null,today.minusYears(30), null, null, LocalDate.now())); + null, null,today.minusYears(30), null, null, LocalDate.now(), false)); } default MemberProfile createADefaultMemberProfileWithBirthDayNotToday() { @@ -30,7 +30,7 @@ default MemberProfile createADefaultMemberProfileWithBirthDayNotToday() { null, "Comedic Relief", null, "New York, New York", "billm@objectcomputing.com", "mr-billy-employee-not-today", LocalDate.now().minusDays(3).minusYears(5), "is a clay figurine clown star of a parody of children's clay animation shows", - null, null, today.minusYears(30).minusDays(3), null, null, LocalDate.now())); + null, null, today.minusYears(30).minusDays(3), null, null, LocalDate.now(), false)); } default MemberProfile createADefaultMemberProfileWithAnniversaryToday() { @@ -39,7 +39,7 @@ default MemberProfile createADefaultMemberProfileWithAnniversaryToday() { null, "Comedic Relief", null, "New York, New York", "billm@objectcomputing.com", "mr-billish-employee", today.minusYears(10), "is a clay figurine clown star of a parody of children's clay animation shows", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createASecondDefaultMemberProfile() { @@ -47,7 +47,7 @@ default MemberProfile createASecondDefaultMemberProfile() { null, "Office Opossum", null, "New York, New York", "slimjim@objectcomputing.com", "slim-jim-employee", LocalDate.now().minusDays(3).minusYears(5), "A Virginia opossum, one of North America's only marsupials", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createAThirdDefaultMemberProfile() { @@ -55,7 +55,7 @@ default MemberProfile createAThirdDefaultMemberProfile() { null, "magic factory owner", null, "Chocolate Factory", "wonkaw@objectcomputing.com", "willy-wonka-employee", LocalDate.now().minusDays(3).minusYears(5), "questionable employer, but gives free golden tickets", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createADefaultMemberProfileForPdl(MemberProfile memberProfile) { @@ -63,7 +63,7 @@ default MemberProfile createADefaultMemberProfileForPdl(MemberProfile memberProf null, "Comedic Relief PDL", memberProfile.getId(), "New York, New York", "billmpdl@objectcomputing.com", "mr-bill-employee-pdl", LocalDate.now().minusDays(3).minusYears(5), "is a clay figurine clown star of a parody of children's clay animation shows", - memberProfile.getId(), null, null, null, null, LocalDate.now())); + memberProfile.getId(), null, null, null, null, LocalDate.now(), false)); } default MemberProfile createASecondDefaultMemberProfileForPdl(MemberProfile memberProfile) { @@ -71,7 +71,7 @@ default MemberProfile createASecondDefaultMemberProfileForPdl(MemberProfile memb null, "Bully Relief PDL", memberProfile.getId(), "New York, New York", "sluggopdl@objectcomputing.com", "sluggo-employee-pdl", LocalDate.now(), "is the bully in a clay figurine clown star of a parody of children's clay animation shows", - memberProfile.getId(), null, null, null, null, LocalDate.now())); + memberProfile.getId(), null, null, null, null, LocalDate.now(), false)); } default MemberProfile createAThirdDefaultMemberProfileForPdl(MemberProfile memberProfile) { @@ -79,7 +79,7 @@ default MemberProfile createAThirdDefaultMemberProfileForPdl(MemberProfile membe null, "local kaiju", memberProfile.getId(), "Tokyo, Japan", "godzilla@objectcomputing.com", "godzilla", LocalDate.now(), "is a destroyer of words", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createADefaultSupervisor() { @@ -87,7 +87,7 @@ default MemberProfile createADefaultSupervisor() { null, "Supervisor Man", null, "New York, New York", "dubebro@objectcomputing.com", "dude-bro-supervisor", LocalDate.now().minusDays(3).minusYears(5), "is such like a bro dude, you know?", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createAnotherSupervisor() { @@ -95,7 +95,7 @@ default MemberProfile createAnotherSupervisor() { null, "Supervisor Lady", null, "New York, New York", "dudettegal@objectcomputing.com", "dudette-gal-supervisor", LocalDate.now().minusDays(5).minusYears(7), "is such like a gal dudette, you know?", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createAProfileWithSupervisorAndPDL(MemberProfile supervisorProfile, MemberProfile pdlProfile) { @@ -103,21 +103,21 @@ default MemberProfile createAProfileWithSupervisorAndPDL(MemberProfile superviso null, "Local fire hazard", pdlProfile.getId(), "New York, New York", "charizard@objectcomputing.com", "local-kaiju", LocalDate.now().minusDays(3).minusYears(5), "Needs a lot of supervision due to building being ultra flammable", - supervisorProfile.getId(), null, null, null, null, LocalDate.now())); + supervisorProfile.getId(), null, null, null, null, LocalDate.now(), false)); } default MemberProfile createAnotherProfileWithSupervisorAndPDL(MemberProfile supervisorProfile, MemberProfile pdlProfile) { return getMemberProfileRepository().save(new MemberProfile("Pikachu", null, "Pika", null, "Local lightning hazard", pdlProfile.getId(), "New York, New York", "pikachu@objectcomputing.com", "local-lightning-kaiju", LocalDate.now().minusDays(5).minusYears(3), "Pretty sparky", - supervisorProfile.getId(), null, null, null, null, LocalDate.now())); + supervisorProfile.getId(), null, null, null, null, LocalDate.now(), false)); } default MemberProfile createYetAnotherProfileWithSupervisorAndPDL(MemberProfile supervisorProfile, MemberProfile pdlProfile) { return getMemberProfileRepository().save(new MemberProfile("Squirtle", null, "Squirt", null, "Local water hazard", pdlProfile.getId(), "New York, New York", "squirtle@objectcomputing.com", "local-water-kaiju", LocalDate.now().minusDays(4).minusYears(6), "Rather moist", - supervisorProfile.getId(), null, null, null, null, LocalDate.now())); + supervisorProfile.getId(), null, null, null, null, LocalDate.now(), false)); } // this user is not connected to other users in the system default MemberProfile createAnUnrelatedUser() { @@ -125,7 +125,7 @@ default MemberProfile createAnUnrelatedUser() { null, "Comedic Relief", null, "New York, New York", "nobody@objectcomputing.com", "mr-bill-employee-unrelated", LocalDate.now().minusDays(3).minusMonths(1).minusYears(5), "is a clay figurine clown star of a parody of children's clay animation shows", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createAPastTerminatedMemberProfile() { @@ -133,7 +133,7 @@ default MemberProfile createAPastTerminatedMemberProfile() { null, "Bully Relief PDL", null, "New York, New York", "sluggopdl@objectcomputing.com", "sluggo-employee-pdl-past-terminated", LocalDate.now().minusDays(3).minusYears(5), "is the bully in a clay figurine clown star of a parody of children's clay animation shows", - null, LocalDate.now().minusMonths(1), null, null, null, LocalDate.now().minusMonths(1))); + null, LocalDate.now().minusMonths(1), null, null, null, LocalDate.now().minusMonths(1), false)); } default MemberProfile createAFutureTerminatedMemberProfile() { @@ -141,7 +141,7 @@ default MemberProfile createAFutureTerminatedMemberProfile() { null, "Bully Relief PDL", null, "New York, New York", "sluggopdl@objectcomputing.com", "sluggo-employee-pdl-future terminated", LocalDate.now().minusDays(3).minusYears(5), "is the bully in a clay figurine clown star of a parody of children's clay animation shows", - null, LocalDate.now().plusDays(7), null, null, null, LocalDate.now().plusDays(7))); + null, LocalDate.now().plusDays(7), null, null, null, LocalDate.now().plusDays(7), false)); } @@ -150,7 +150,16 @@ default MemberProfile createADefaultMemberProfileWithBirthDay() { null, "Comedic Relief", null, "New York, New York", "billm@objectcomputing.com", "mr-bill-employee-birthday", LocalDate.now().minusDays(3).minusYears(5), "is a clay figurine clown star of a parody of children's clay animation shows", - null, null, LocalDate.now(), null, null, LocalDate.now())); + null, null, LocalDate.now(), null, null, LocalDate.now(), false)); + } + + // This user is disconnected and doesn't want their birthday celebrated. + default MemberProfile createUserWithIgnoredBirthday() { + return getMemberProfileRepository().save(new MemberProfile("Gone", null, " Girl", + null, "Video Vogue", null, "New York, New York", + "girlg@objectcomputing.com", "stay-away-from-me", + LocalDate.now().minusDays(3).minusYears(5), "is gone, girl!", + null, null, null, null, null, LocalDate.now(), true)); } default MemberProfile createAPastMemberProfile() { @@ -158,7 +167,7 @@ default MemberProfile createAPastMemberProfile() { null, "Comedic Relief", null, "New York, New York", "billm@objectcomputing.com", "mr-bill-employee-past", LocalDate.now().minusYears(2), "is a clay figurine clown star of a parody of children's clay animation shows", - null, null, null, null, null, LocalDate.now().minusYears(2))); + null, null, null, null, null, LocalDate.now().minusYears(2), false)); } default MemberProfile createANewHireProfile() { @@ -166,7 +175,7 @@ default MemberProfile createANewHireProfile() { null, "Comedic Relief", null, "New York, New York", "billm@objectcomputing.com", "mr-bill-employee-new", LocalDate.now().minusMonths(2), "is a clay figurine clown star of a parody of children's clay animation shows", - null, null, null, null, null, LocalDate.now())); + null, null, null, null, null, LocalDate.now(), false)); } default MemberProfile createATerminatedNewHireProfile() { @@ -174,7 +183,7 @@ default MemberProfile createATerminatedNewHireProfile() { null, "Comedic Relief", null, "New York, New York", "billm@objectcomputing.com", "mr-bill-employee-term-new", LocalDate.now().minusMonths(2), "is a clay figurine clown star of a parody of children's clay animation shows", - null, LocalDate.now().minusMonths(1), null, true, null, LocalDate.now().minusMonths(1))); + null, LocalDate.now().minusMonths(1), null, true, null, LocalDate.now().minusMonths(1), false)); } default MemberProfile memberWithoutBoss(String name) { @@ -204,7 +213,8 @@ default MemberProfile memberWithSupervisor(String name, MemberProfile supervisor null, null, null, - LocalDate.now() + LocalDate.now(), + false ) ); } diff --git a/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileTest.java b/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileTest.java index c74478a861..56e8e4b782 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileTest.java @@ -65,7 +65,7 @@ void testMemberProfileInstantiation() { MemberProfile memberProfile = new MemberProfile(firstName, null, lastName, null, null, null, null, workEmail, null, null, null, null, - null, null, null, null, null); + null, null, null, null, null, false); assertEquals(firstName, memberProfile.getFirstName()); assertEquals(lastName, memberProfile.getLastName()); assertEquals(workEmail, memberProfile.getWorkEmail()); @@ -79,7 +79,7 @@ void testConstraintViolation() { MemberProfile memberProfile = new MemberProfile(firstName, null, lastName, null, null, null, null, workEmail, null, null, null, null, - null, null, null, null, null); + null, null, null, null, null, false); assertEquals(firstName, memberProfile.getFirstName()); assertEquals(lastName, memberProfile.getLastName()); assertEquals(workEmail, memberProfile.getWorkEmail()); @@ -113,7 +113,7 @@ void testEquals() { LocalDate lastSeen = LocalDate.now(); MemberProfile memberProfile = new MemberProfile(id, firstName, middleName, lastName, suffix, title, pdlId, location, workEmail, - employeeId, startDate, bioText, supervisorId, terminationDate, birthDate, voluntary, excluded, lastSeen); + employeeId, startDate, bioText, supervisorId, terminationDate, birthDate, voluntary, excluded, lastSeen, false); assertEquals(id, memberProfile.getId()); assertEquals(firstName, memberProfile.getFirstName()); @@ -157,7 +157,7 @@ void testToString() { final LocalDate lastSeen = LocalDate.now(); MemberProfile memberProfile = new MemberProfile(id, firstName, middleName, lastName, suffix, title, pdlId, location, workEmail, - employeeId, startDate, bioText, supervisorId, terminationDate, birthDate, voluntary, excluded, lastSeen); + employeeId, startDate, bioText, supervisorId, terminationDate, birthDate, voluntary, excluded, lastSeen, false); String toString = memberProfile.toString(); assertTrue(toString.contains(id.toString())); @@ -184,7 +184,7 @@ void testToString() { void testSaveProfileWithExistingEmail() { MemberProfile existingProfile = createADefaultMemberProfile(); String workEmail = existingProfile.getWorkEmail(); - MemberProfile newProfile = new MemberProfile(UUID.randomUUID(), "John", null, "Smith", null, null, null, null, workEmail, null, null, null, null, null, null, null, null, null); + MemberProfile newProfile = new MemberProfile(UUID.randomUUID(), "John", null, "Smith", null, null, null, null, workEmail, null, null, null, null, null, null, null, null, null, false); // The current user must have permission to create new members. currentUserServices.currentUser = existingProfile; @@ -203,7 +203,7 @@ void testSaveProfileWithNewEmail() { LocalDate.now().minusDays(3).minusYears(5), "Needs supervision due to building being ultra flammable", supervisorProfile.getId(), null, null, null, null, - LocalDate.now()); + LocalDate.now(), false); // Need permission to create new profiles. currentUserServices.currentUser = supervisorProfile; @@ -239,7 +239,7 @@ void testUpdateProfileWithChangedPDL() { currentUserServices.currentUser = existingProfile; - MemberProfile updatedProfile = new MemberProfile(id, existingProfile.getFirstName(), null, existingProfile.getLastName(), null, null, pdlId, null, existingProfile.getWorkEmail(), null, null, null, null, null, null, null, null, null); + MemberProfile updatedProfile = new MemberProfile(id, existingProfile.getFirstName(), null, existingProfile.getLastName(), null, null, pdlId, null, existingProfile.getWorkEmail(), null, null, null, null, null, null, null, null, null, false); MemberProfile result = memberProfileServices.updateProfile(updatedProfile); @@ -264,7 +264,7 @@ void testUpdateProfileWithChangedSupervisor() { currentUserServices.currentUser = existingProfile; - MemberProfile updatedProfile = new MemberProfile(id, existingProfile.getFirstName(), null, existingProfile.getLastName(), null, null, null, null, existingProfile.getWorkEmail(), null, null, null, supervisorId, null, null, null, null, null); + MemberProfile updatedProfile = new MemberProfile(id, existingProfile.getFirstName(), null, existingProfile.getLastName(), null, null, null, null, existingProfile.getWorkEmail(), null, null, null, supervisorId, null, null, null, null, null, false); MemberProfile result = memberProfileServices.updateProfile(updatedProfile); @@ -356,7 +356,7 @@ void testEmailAssignmentWithValidPdlAndSupervisor() { void testEmailAssignmentWithInvalidPDL() { MemberProfile existingProfile = createADefaultMemberProfile(); UUID pdlId = UUID.randomUUID(); - MemberProfile member = new MemberProfile(existingProfile.getId(), existingProfile.getFirstName(), null, existingProfile.getLastName(), null, null, pdlId, null, existingProfile.getWorkEmail(), null, null, null, null, null, null, null, null, null); + MemberProfile member = new MemberProfile(existingProfile.getId(), existingProfile.getFirstName(), null, existingProfile.getLastName(), null, null, pdlId, null, existingProfile.getWorkEmail(), null, null, null, null, null, null, null, null, null, false); memberProfileServices.emailAssignment(member, true); @@ -367,7 +367,7 @@ void testEmailAssignmentWithInvalidPDL() { void testEmailAssignmentWithInvalidSupervisor() { MemberProfile existingProfile = createADefaultMemberProfile(); UUID supervisorId = UUID.randomUUID(); - MemberProfile member = new MemberProfile(existingProfile.getId(), existingProfile.getFirstName(), null, existingProfile.getLastName(), null, null, null, null, existingProfile.getWorkEmail(), null, null, null, supervisorId, null, null, null, null, null); + MemberProfile member = new MemberProfile(existingProfile.getId(), existingProfile.getFirstName(), null, existingProfile.getLastName(), null, null, null, null, existingProfile.getWorkEmail(), null, null, null, supervisorId, null, null, null, null, null, false); memberProfileServices.emailAssignment(member, true); @@ -377,7 +377,7 @@ void testEmailAssignmentWithInvalidSupervisor() { @Test void testEmailAssignmentWithInvalidMember() { MemberProfile member = new MemberProfile(UUID.randomUUID(), "John", null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, null); + null, null, null, null, null, null, null, null, null, false); memberProfileServices.emailAssignment(member, true); @@ -387,7 +387,7 @@ void testEmailAssignmentWithInvalidMember() { @Test void testEmailAssignmentWithNullRoleId() { MemberProfile member = new MemberProfile(UUID.randomUUID(), "John", null, "Smith", null, null, null, null, "john.smith@example.com", - null, null, null, null, null, null, null, null, null); + null, null, null, null, null, null, null, null, null, false); memberProfileServices.emailAssignment(member, true); diff --git a/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileTestUtil.java b/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileTestUtil.java index 8a86defce3..c436bea2d4 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileTestUtil.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/MemberProfileTestUtil.java @@ -51,7 +51,7 @@ public static MemberProfile mkMemberProfile(String seed) { LocalDate.of(2019, 1, 1), "TestBio" + seed, null, - null,null, null, null, LocalDate.now()); + null,null, null, null, LocalDate.now(), false); } public static MemberProfile mkMemberProfile() { diff --git a/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/birthday/BirthDayControllerTest.java b/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/birthday/BirthDayControllerTest.java index 31a7e4a996..8414bd4e3c 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/birthday/BirthDayControllerTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/birthday/BirthDayControllerTest.java @@ -81,4 +81,23 @@ void testGETFindByValueNameOfTheMonthNotAuthorized() { assertEquals(HttpStatus.FORBIDDEN, thrown.getStatus()); } + + @Test + void testGETFindByValueDoesNotIncludeIgnoredBirthdays() { + + MemberProfile memberProfileOfAdmin = createAnUnrelatedUser(); + assignAdminRole(memberProfileOfAdmin); + + MemberProfile memberProfile = createADefaultMemberProfileWithBirthDay(); + MemberProfile ignoredMember = createUserWithIgnoredBirthday(); + + final HttpRequest request = HttpRequest. + GET(String.format("/?month=%s", memberProfile.getBirthDate().getMonth().toString())).basicAuth(memberProfileOfAdmin.getWorkEmail(), ADMIN_ROLE); + + final HttpResponse> response = client.toBlocking().exchange(request, Argument.listOf(BirthDayResponseDTO.class)); + + assertEquals(1, response.body().size()); + assertEquals(memberProfile.getId(), response.body().get(0).getUserId()); + assertEquals(HttpStatus.OK, response.getStatus()); + } } diff --git a/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/currentuser/CurrentUserDtoTest.java b/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/currentuser/CurrentUserDtoTest.java index 2896592e57..6de8a0bd0e 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/currentuser/CurrentUserDtoTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/memberprofile/currentuser/CurrentUserDtoTest.java @@ -2,6 +2,7 @@ import com.objectcomputing.checkins.services.TestContainersSuite; import com.objectcomputing.checkins.services.memberprofile.MemberProfile; +import com.objectcomputing.checkins.services.memberprofile.MemberProfileResponseDTO; import io.micronaut.validation.validator.Validator; import jakarta.inject.Inject; import jakarta.validation.ConstraintViolation; @@ -54,7 +55,7 @@ void testPopulatedDTO() { assertEquals("some.last.name", dto.getLastName()); dto.setName(dto.getFirstName() + ' ' + dto.getLastName()); - dto.setMemberProfile(new MemberProfile()); + dto.setMemberProfile(new MemberProfileResponseDTO()); Set> violations = validator.validate(dto); assertTrue(violations.isEmpty()); diff --git a/web-ui/src/context/actions.js b/web-ui/src/context/actions.js index c51b7e707b..5e97a4b95a 100644 --- a/web-ui/src/context/actions.js +++ b/web-ui/src/context/actions.js @@ -28,6 +28,7 @@ export const UPDATE_TEAMS = '@@check-ins/update_teams'; export const UPDATE_TERMINATED_MEMBERS = '@@check-ins/update_terminated_members'; export const UPDATE_TOAST = '@@check-ins/update_toast'; +export const UPDATE_CURRENT_USER_PROFILE = '@@check-ins/update_current_user_profile'; export const UPDATE_USER_BIO = '@@check-ins/update_bio'; export const UPDATE_FEEEDBACK_SUGGESTIONS = '@@check-ins/update_feedback_suggestions'; diff --git a/web-ui/src/context/reducer.js b/web-ui/src/context/reducer.js index 6c484898d9..541d5184ae 100644 --- a/web-ui/src/context/reducer.js +++ b/web-ui/src/context/reducer.js @@ -27,7 +27,7 @@ import { UPDATE_TEAMS, UPDATE_TEAM_MEMBERS, UPDATE_TOAST, - UPDATE_USER_BIO, + UPDATE_CURRENT_USER_PROFILE, UPDATE_PEOPLE_LOADING, UPDATE_TEAMS_LOADING, UPDATE_REVIEW_PERIOD, @@ -59,13 +59,42 @@ export const initialState = { reviewPeriods: [] }; +// Converts member dates *in place*, I don't love this. I'll be back, convertMemberDates...don't get comfortable. +const convertMemberDates = member => { + member.birthDay = Array.isArray(member.birthDay) + ? new Date(member.birthDay.join('/')) + : member && member.birthDay + ? member.birthDay + : null; + member.startDate = Array.isArray(member.startDate) + ? new Date(member.startDate.join('/')) + : member && member.startDate + ? member.startDate + : new Date(); + member.terminationDate = Array.isArray(member.terminationDate) + ? new Date(member.terminationDate.join('/')) + : member && member.terminationDate + ? member.terminationDate + : null; +}; + export const reducer = (state, action) => { switch (action.type) { case MY_PROFILE_UPDATE: - state.userProfile = action.payload; - break; - case UPDATE_USER_BIO: - state.userProfile.memberProfile.bioText = action.payload; + convertMemberDates(action.payload.memberProfile); + state.userProfile = { ...action.payload }; + break; + case UPDATE_CURRENT_USER_PROFILE: + convertMemberDates(action.payload); + state.userProfile = { ...state.userProfile, memberProfile: { ...action.payload } }; + const profileId = action.payload.id; + const memberProfiles = state.memberProfiles.reduce((acc, current) => { + if(current.id !== profileId) { + acc.push({...current}); + } + return acc; + }, [{ ...action.payload }]) + state.memberProfiles = memberProfiles; break; case ADD_CHECKIN: if (state?.checkins?.length > 0) { @@ -144,43 +173,20 @@ export const reducer = (state, action) => { state.loading = { ...state.loading, memberProfiles: action.payload }; break; case UPDATE_MEMBER_PROFILES: - action.payload.forEach(member => { - member.birthDay = Array.isArray(member.birthDay) - ? new Date(member.birthDay.join('/')) - : member && member.birthDay - ? member.birthDay - : null; - member.startDate = Array.isArray(member.startDate) - ? new Date(member.startDate.join('/')) - : member && member.startDate - ? member.startDate - : new Date(); - member.terminationDate = Array.isArray(member.terminationDate) - ? new Date(member.terminationDate.join('/')) - : member && member.terminationDate - ? member.terminationDate - : null; + action.payload.forEach(convertMemberDates); + const currentProfileId = state?.userProfile?.memberProfile?.id; + const currentProfile = action.payload.find((current) => { + if(currentProfileId && current.id === currentProfileId) { + return current; + } }); + if(currentProfile) { + state.userProfile.memberProfile = { ...currentProfile }; + } state.memberProfiles = action.payload; break; case UPDATE_TERMINATED_MEMBERS: - action.payload.forEach(member => { - member.birthDay = Array.isArray(member.birthDay) - ? new Date(member.birthDay.join('/')) - : member && member.birthDay - ? member.birthDay - : null; - member.startDate = Array.isArray(member.startDate) - ? new Date(member.startDate.join('/')) - : member && member.startDate - ? member.startDate - : new Date(); - member.terminationDate = Array.isArray(member.terminationDate) - ? new Date(member.terminationDate.join('/')) - : member && member.terminationDate - ? member.terminationDate - : null; - }); + action.payload.forEach(convertMemberDates); state.terminatedMembers = action.payload; break; case UPDATE_TEAM_MEMBERS: diff --git a/web-ui/src/pages/ProfilePage.jsx b/web-ui/src/pages/ProfilePage.jsx index 7adee7e709..70983e7708 100644 --- a/web-ui/src/pages/ProfilePage.jsx +++ b/web-ui/src/pages/ProfilePage.jsx @@ -5,10 +5,9 @@ import { AppContext } from '../context/AppContext'; import { selectCurrentUser, selectMyGuilds, - selectUserProfile, selectMyTeams } from '../context/selectors'; -import { UPDATE_GUILD, UPDATE_USER_BIO } from '../context/actions'; +import { UPDATE_GUILD, UPDATE_CURRENT_USER_PROFILE } from '../context/actions'; import { addGuildMember, deleteGuildMember } from '../api/guild'; import { updateMember } from '../api/member'; import { getEmployeeHours } from '../api/hours'; @@ -18,10 +17,15 @@ import SkillSection from '../components/skills/SkillSection'; import ProgressBar from '../components/contribution_hours/ProgressBar'; import VolunteerTables from '../components/volunteer/VolunteerTables'; -import { Info } from '@mui/icons-material'; +import { Info, ManageAccounts } from '@mui/icons-material'; import { Card, CardContent, CardHeader, Chip, TextField, Avatar } from '@mui/material'; import GroupIcon from '@mui/icons-material/Group'; import Autocomplete from '@mui/material/Autocomplete'; +import FormLabel from '@mui/material/FormLabel'; +import FormControl from '@mui/material/FormControl'; +import FormGroup from '@mui/material/FormGroup'; +import FormControlLabel from '@mui/material/FormControlLabel'; +import Switch from '@mui/material/Switch'; import './ProfilePage.css'; @@ -32,13 +36,12 @@ const storeMember = debounce(realStoreMember, 1500); const ProfilePage = () => { const { state, dispatch } = useContext(AppContext); const memberProfile = selectCurrentUser(state); - const userProfile = selectUserProfile(state); const { csrf, guilds } = state; - const { id, bioText, pdlId } = memberProfile; - const { firstName, lastName, name } = userProfile; + const { id, bioText, pdlId, ignoreBirthday, firstName, lastName, name } = memberProfile; const [bio, setBio] = useState(); + const [prefs, setPrefs] = useState({ignoreBirthday}); const [myHours, setMyHours] = useState(null); const myTeams = selectMyTeams(state); @@ -62,24 +65,43 @@ const ProfilePage = () => { setBio(bioText); } updateBio(); - }, [bioText]); + }, [setBio, bioText]); - const updateProfile = newBio => { + useEffect(() => { + async function updatePrefs() { + setPrefs({...prefs, ignoreBirthday}) + } + updatePrefs() + }, [setPrefs, ignoreBirthday]); + + const updateProfile = newProfile => { dispatch({ - type: UPDATE_USER_BIO, - payload: newBio + type: UPDATE_CURRENT_USER_PROFILE, + payload: newProfile }); }; - const handleBioChange = e => { + const handleIgnoreBirthdayChange = useCallback(async e => { + if (!csrf) { + return; + } + const { checked } = e.target; + setPrefs({ ...prefs, ignoreBirthday: !checked }); + const newProfile = { ...memberProfile, ignoreBirthday: !checked }; + const { payload } = await realStoreMember(newProfile, csrf); + updateProfile(payload.data); + }, [csrf, prefs, setPrefs, memberProfile, realStoreMember, updateProfile]); + + const handleBioChange = useCallback(async e => { if (!csrf) { return; } const { value } = e.target; setBio(value); - storeMember({ ...memberProfile, bioText: value }, csrf); - updateProfile(value); - }; + const newProfile = { ...memberProfile, bioText: value }; + storeMember(newProfile, csrf); + updateProfile(newProfile); + }, [csrf, setBio, memberProfile, storeMember, updateProfile]); const addOrDeleteGuildMember = useCallback( async newVal => { @@ -146,6 +168,28 @@ const ProfilePage = () => {
+
+ + } + title="Preferences" + titleTypographyProps={{ variant: 'h5', component: 'h2' }} + /> + + + Celebrations + + + } + label="My Birthday" + /> + + + + +
+
+
+
+
+
+ +
+
+
+

+ Preferences +

+
+
+
+
+ + Celebrations + +
+ +
+
+
+
+