Fix Event-Type 404 in case of unintentional duplicates. (#3049)
* Fix sort order to ensure correct event-type is picked when duplicates * Refetch after mutation to ensure that after positioning is changed, UI is updated * Dont rely on hashmap for ordering. Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
624a7a036d
commit
5653282dea
3 files changed
+19
-8
No files matched your search
@@ -116,6 +116,16 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
},
|
||||
],
|
||||
},
|
||||
// Order is important to ensure that given a slug if there are duplicates, we choose the same event type consistently when showing in event-types list UI(in terms of ordering and disabled event types)
|
||||
// TODO: If we can ensure that there are no duplicates for a [slug, userId] combination in existing data, this requirement might be avoided.
|
||||
orderBy: [
|
||||
{
|
||||
position: "desc",
|
||||
},
|
||||
{
|
||||
id: "asc",
|
||||
},
|
||||
],
|
||||
select: {
|
||||
...availiblityPageEventTypeSelect,
|
||||
users: {
|
||||
@@ -170,6 +180,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!eventTypeBackwardsCompat) {
|
||||
return {
|
||||
notFound: true,
|
||||
@@ -187,9 +198,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
|
||||
user.eventTypes.push(eventTypeBackwardsCompat);
|
||||
}
|
||||
|
||||
let [eventType] = user.eventTypes;
|
||||
|
||||
if (isDynamicGroup) {
|
||||
eventType = getDefaultEvent(typeParam);
|
||||
eventType["users"] = users.map((user) => {
|
||||
|
||||
@@ -116,6 +116,9 @@ export const EventTypeList = ({ group, groupIndex, readOnly, types }: EventTypeL
|
||||
await utils.cancelQuery(["viewer.eventTypes"]);
|
||||
await utils.invalidateQueries(["viewer.eventTypes"]);
|
||||
},
|
||||
onSettled: async () => {
|
||||
await utils.invalidateQueries(["viewer.eventTypes"]);
|
||||
},
|
||||
});
|
||||
|
||||
function moveEventType(index: number, increment: 1 | -1) {
|
||||
|
||||
@@ -239,15 +239,14 @@ const loggedInViewerRouter = createProtectedRouter()
|
||||
};
|
||||
|
||||
let eventTypeGroups: EventTypeGroup[] = [];
|
||||
const eventTypesHashMap = user.eventTypes.concat(typesRaw).reduce((hashMap, newItem) => {
|
||||
const oldItem = hashMap[newItem.id] || {};
|
||||
const eventTypesHashMap = user.eventTypes.concat(typesRaw).reduce((hashMap, newItem, currentIndex) => {
|
||||
const oldItem = hashMap[newItem.id] || {
|
||||
$disabled: user.plan === "FREE" && currentIndex > 0,
|
||||
};
|
||||
hashMap[newItem.id] = { ...oldItem, ...newItem };
|
||||
return hashMap;
|
||||
}, {} as Record<number, EventTypeGroup["eventTypes"][number]>);
|
||||
const mergedEventTypes = Object.values(eventTypesHashMap).map((et, index) => ({
|
||||
...et,
|
||||
$disabled: user.plan === "FREE" && index > 0,
|
||||
}));
|
||||
const mergedEventTypes = Object.values(eventTypesHashMap).map((eventType) => eventType);
|
||||
|
||||
eventTypeGroups.push({
|
||||
teamId: null,
|
||||
|
||||
Reference in new issue
Block a user