Skip to content

Commit

Permalink
[front] - refactor: extract user image URL logic into a separate func…
Browse files Browse the repository at this point in the history
…tion

 - Centralizes the retrieval of a user's image URL in a single function for better code reusability
 - Updates `getServerSideProps` to use the new function when fetching user image URL for data source objects
  • Loading branch information
Jules authored and Jules committed Aug 5, 2024
1 parent b4da795 commit d43b49b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions front/pages/w/[wId]/builder/data-sources/managed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export async function setupConnection({
return new Ok(connectionId);
}

function getUserImageUrl(dataSource: DataSourceType) {
return dataSource.editedByUser?.imageUrl ?? null;
}

export const getServerSideProps = withDefaultUserAuthRequirements<{
owner: WorkspaceType;
subscription: SubscriptionType;
Expand Down Expand Up @@ -207,7 +211,7 @@ export const getServerSideProps = withDefaultUserAuthRequirements<{
connector: null,
fetchConnectorError: true,
fetchConnectorErrorMessage: statusRes.error.message,
editedByUser: mds.editedByUser?.imageUrl ?? null,
editedByUser: getUserImageUrl(mds),
usage: await getDataSourceUsage({
auth,
dataSource: mds,
Expand All @@ -220,7 +224,7 @@ export const getServerSideProps = withDefaultUserAuthRequirements<{
connector: statusRes.value,
fetchConnectorError: false,
fetchConnectorErrorMessage: null,
editedByUser: mds.editedByUser?.imageUrl ?? null,
editedByUser: getUserImageUrl(mds),
usage: await getDataSourceUsage({
auth,
dataSource: mds,
Expand All @@ -236,7 +240,7 @@ export const getServerSideProps = withDefaultUserAuthRequirements<{
connector: null,
fetchConnectorError: true,
fetchConnectorErrorMessage: "Synchonization service is down",
editedByUser: mds.editedByUser?.imageUrl ?? "",
editedByUser: getUserImageUrl(mds),
usage: null,
};
}
Expand Down

0 comments on commit d43b49b

Please sign in to comment.