Skip to content

Commit

Permalink
Fix serialization for Kotlinx Instant (#10)
Browse files Browse the repository at this point in the history
* Fix serialization for kotlinx Instant

* Handle undefined value

* Bump to Client v.1.2.0
  • Loading branch information
yuanchen233 authored Sep 20, 2024
1 parent 6102d3a commit cfdd6ce
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@babel/plugin-transform-react-jsx-self": "^7.24.7",
"@babel/plugin-transform-react-jsx-source": "^7.24.7",
"@carp-dk/authentication-react": "^1.0.1",
"@carp-dk/client": "1.1.0",
"@carp-dk/client": "1.2.0",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@js-joda/core": "^5.6.2",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Deployments/DeploymentCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const DeploymentCard = ({
() =>
deployment.participants
.map((participant) =>
participant.firstName !== null
participant.firstName
? `${participant.firstName} ${participant.lastName}`
: "",
)
Expand Down
11 changes: 9 additions & 2 deletions src/pages/Deployments/ParticipantRecord/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ const ParticipantRecord = ({
);
const participantDeviceType = primaryDevice.device.__type;
const deviceStatus = primaryDevice.__type.split(".").pop();
if (participantData.firstName === undefined) {
participantData.firstName = "";
}
if (participantData.lastName === undefined) {
participantData.lastName = "";
}

const lastDataUpload = useMemo(() => {
const lastData = participantData.dateOfLastDataUpload;
if (lastData === null) {
if (!lastData) {
return "";
}
const elapsedDays = calculateDaysPassedFromDate(
lastData.value$kotlinx_datetime.toString(),
lastData.toString(),
);
if (elapsedDays === 0) {
return "Last data: Today";
Expand Down
17 changes: 7 additions & 10 deletions src/pages/Participant/Deployment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,19 @@ const Deployment = () => {
createSummary.mutateAsync({ studyId, deploymentIds: [deploymentId] });
};

const lastDataUpload = (lastData: {
epocSeconds: number;
value$kotlinx_datetime: Date;
nanosecondsOfSecond: number;
}) => {
if (lastData === null) {
const lastDataUpload = (lastData: Date
) => {
if (!lastData) {
return "";
}
if (
calculateDaysPassedFromDate(
lastData.value$kotlinx_datetime.toString(),
lastData.toString(),
) === 0
) {
return "Last data: Today";
}
return `Last data: ${calculateDaysPassedFromDate(lastData.value$kotlinx_datetime.toString())} days ago`;
return `Last data: ${calculateDaysPassedFromDate(lastData.toString())} days ago`;
};

useEffect(() => {
Expand Down Expand Up @@ -129,9 +126,9 @@ const Deployment = () => {
const getParticipantInitials = (participant: ParticipantData) => {
if (
participant.firstName === "" ||
participant.firstName === null ||
participant.lastName === "" ||
participant.lastName === null
!participant.firstName ||
!participant.lastName
) {
return participant.role ? participant.role[0] : "?";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const validationSchema = yup.object({
.number()
.required("Number of participants is required")
.min(1, "Number of participants must be at least 1")
.max(1000, "Number of participants must be at most 1000"),
.max(2500, "Number of participants must be at most 2500"),
expiryDate: yup
.date()
.required("Expiry date is required")
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Studies/StudiesSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const StudiesSection = ({ isAdmin }: StudiesProps) => {
studies &&
studies
.sort((a, b) =>
a.createdOn.value$kotlinx_datetime <
b.createdOn.value$kotlinx_datetime
a.createdOn <
b.createdOn
? 1
: -1,
)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Studies/StudyCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const StudyCard = ({ onClick, study, status, description }: Props) => {
<Bottom>
<CreationText variant="h5">
{formatDateTime(
study.createdOn.value$kotlinx_datetime.toString(),
study.createdOn.toString(),
)}
</CreationText>
{/* TODO: Add real owner name after backend supports it */}
Expand Down

0 comments on commit cfdd6ce

Please sign in to comment.