Skip to content

Commit

Permalink
fix: Add creator_id into CreateFlow mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jan 25, 2022
1 parent e3538f8 commit 67bb8b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
18 changes: 16 additions & 2 deletions editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import debounce from "lodash/debounce";
import isEmpty from "lodash/isEmpty";
import omitBy from "lodash/omitBy";
import type { FlowSettings, TextContent } from "types";
import { getLoggedInUserId } from "utils";
import type { GetState, SetState } from "zustand/vanilla";

import { FlowLayout } from "../../components/Flow";
Expand Down Expand Up @@ -147,11 +148,23 @@ export const editorStore = (

createFlow: async (teamId, newSlug) => {
const data = { [ROOT_NODE_KEY]: { edges: [] } };
const creatorId = getLoggedInUserId();
let response = (await client.mutate({
mutation: gql`
mutation CreateFlow($data: jsonb, $slug: String, $teamId: Int) {
mutation CreateFlow(
$data: jsonb
$slug: String
$teamId: Int
$creatorId: Int
) {
insert_flows_one(
object: { data: $data, slug: $slug, team_id: $teamId, version: 1 }
object: {
data: $data
slug: $slug
team_id: $teamId
version: 1
creator_id: $creatorId
}
) {
id
data
Expand All @@ -162,6 +175,7 @@ export const editorStore = (
slug: newSlug,
teamId,
data,
creatorId,
},
})) as any;

Expand Down
13 changes: 13 additions & 0 deletions editor.planx.uk/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import jwtDecode from "jwt-decode";

import { getCookie } from "./lib/cookie";

export function removeAt<T>(index: number, arr: Array<T>): Array<T> {
return arr.filter((_item, i) => {
return i !== index;
Expand Down Expand Up @@ -52,3 +56,12 @@ export function slugify(name: string): string {
.replace(/[\s_-]+/g, "-") // swap any length of whitespace, underscore, hyphen characters with a single -
.replace(/^-+|-+$/g, ""); // remove leading, trailing -
}

export function getLoggedInUserId(): number | undefined {
const jwt = getCookie("jwt");
if (!jwt) return;
const userId = Number(
(jwtDecode(jwt) as any)["https://hasura.io/jwt/claims"]["x-hasura-user-id"]
);
return userId;
}

0 comments on commit 67bb8b5

Please sign in to comment.