Skip to content

Commit

Permalink
lib changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alder Whiteford authored and Alder Whiteford committed Jun 9, 2024
1 parent c764216 commit de676e5
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 1,650 deletions.
2 changes: 1 addition & 1 deletion frontend/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "jest"
},
"dependencies": {
"@generatesac/lib": "^0.0.1",
"@generatesac/lib": "^0.0.11",
"@hookform/resolvers": "^3.4.2",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-label": "^2.0.2",
Expand Down
1,636 changes: 12 additions & 1,624 deletions frontend/dashboard/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@generatesac/lib",
"version": "0.0.1",
"version": "0.0.12",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
20 changes: 10 additions & 10 deletions frontend/lib/src/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export const baseApi = createApi({
baseQuery: fetchBaseQuery({
baseUrl: API_BASE_URL,
credentials: "include",
prepareHeaders: async (headers, { getState }) => {
const token = (getState() as { auth: { token: string } })?.auth.token;
if (token) {
headers.set("Authorization", `Bearer ${token}`);
}
return headers;
},
// prepareHeaders: async (headers, { getState }) => {
// const token = (getState() as { auth: { token: string } })?.auth.token;
// if (token) {
// headers.set("Authorization", `Bearer ${token}`);
// }
// return headers;
// },
}),
tagTypes: [
"User",
Expand All @@ -35,11 +35,11 @@ export function handleQueryParams(
baseUrl: string,
queryParams?: Record<string, string | number | boolean>,
): string {
const url = new URL(baseUrl);
let url = `${baseUrl}?`;
if (queryParams) {
Object.entries(queryParams).forEach(([key, value]) => {
url.searchParams.append(key, value.toString());
url += `${key}=${value}&`
});
}
return url.toString();
return url;
}
9 changes: 3 additions & 6 deletions frontend/lib/src/api/eventApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const eventApi = baseApi.injectEndpoints({
url: handleQueryParams(`${EVENT_API_BASE_URL}/`, queryParams),
method: "GET",
}),
providesTags: (result, _, _arg) =>
providesTags: (result) =>
result
? result.map((event) => ({ type: "Event", id: event.id }))
: ["Event"],
Expand Down Expand Up @@ -49,10 +49,7 @@ export const eventApi = baseApi.injectEndpoints({
return eventSchema.parse(response);
},
}),
updateEvent: builder.mutation<
Event,
{ id: string; body: UpdateEventRequestBody }
>({
updateEvent: builder.mutation<Event, { id: string; body: UpdateEventRequestBody }>({
query: ({ id, body }) => ({
url: `${EVENT_API_BASE_URL}/${id}`,
method: "PATCH",
Expand Down Expand Up @@ -88,7 +85,7 @@ export const eventApi = baseApi.injectEndpoints({
url: `${EVENT_API_BASE_URL}/${id}/tags`,
method: "GET",
}),
providesTags: (result, _, _arg) =>
providesTags: (result) =>
result ? result.map((tag) => ({ type: "Tag", id: tag.id })) : ["Tag"],
}),
}),
Expand Down
15 changes: 9 additions & 6 deletions frontend/lib/src/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { rootModelSchema } from "./root";
*/

// Enums:
const eventTypeEnum = z.enum(["open", "membersOnly"]);
const eventTypeEnum = z.enum(["hybrid", "in_person", "virtual"]);

// Schemas:
const createEventRequestBodySchema = z.object({
Expand Down Expand Up @@ -35,13 +35,16 @@ const updateEventRequestBodySchema = z.object({
const eventSchemaIntermediate = z.object({
name: z.string().max(255),
preview: z.string().max(255),
content: z.string().max(255),
start_time: z.date(),
end_time: z.date(),
description: z.string().max(255),
start_time: z.string(),
end_time: z.string(),
location: z.string().max(255),
meeting_link: z.string().max(255).optional(),
link: z.string().max(255).optional(),
event_type: eventTypeEnum,
is_recurring: z.boolean(),
is_recurring: z.boolean().optional(),
is_public: z.boolean(),
is_draft: z.boolean(),
is_archived: z.boolean(),
host: z.string().uuid(),
});

Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions frontend/lib/src/types/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ export type uuid = string;

export const rootModelSchema = z.object({
id: z.string().uuid(),
created_at: z.date(),
updated_at: z.date(),
created_at: z.string(),
updated_at: z.string(),
});

const paginationQueryParams = z
.object({
page: z.number().int().positive().optional(),
limit: z.number().int().positive().optional(),
start: z.string().optional(),
end: z.string().optional(),
})
.optional();

Expand Down

0 comments on commit de676e5

Please sign in to comment.