Skip to content

Commit

Permalink
feat(shopify): adds signUp action (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriassuncx authored Oct 22, 2024
1 parent 8e5e75c commit 8fd0f4e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shopify/actions/user/signIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface AccessTokenResponse {

/**
* @title Shopify Integration
* @description SignInWithEmailAndPassword Action
* @description Sign In With Email And Password Action
*/
const action = async (
props: Props,
Expand Down
41 changes: 41 additions & 0 deletions shopify/actions/user/signUp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { AppContext } from "../../mod.ts";
import { RegisterAccount } from "../../utils/storefront/queries.ts";
import {
CustomerCreateInput,
CustomerCreatePayload,
} from "../../utils/storefront/storefront.graphql.gen.ts";

interface Props {
email: string;
/**
* @format password
*/
password: string;
firstName: string;
lastName: string;
acceptsMarketing?: boolean;
}

/**
* @title Shopify Integration
* @description Register Account Action
*/
const action = async (
props: Props,
_req: Request,
ctx: AppContext,
): Promise<CustomerCreatePayload> => {
const { storefront } = ctx;

const data = await storefront.query<
{ customerCreate: CustomerCreatePayload },
CustomerCreateInput
>({
variables: props,
...RegisterAccount,
});

return data.customerCreate;
};

export default action;
2 changes: 2 additions & 0 deletions shopify/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as $$$$$$$$$1 from "./actions/cart/updateCoupons.ts";
import * as $$$$$$$$$2 from "./actions/cart/updateItems.ts";
import * as $$$$$$$$$3 from "./actions/order/draftOrderCalculate.ts";
import * as $$$$$$$$$4 from "./actions/user/signIn.ts";
import * as $$$$$$$$$5 from "./actions/user/signUp.ts";
import * as $$$$0 from "./handlers/sitemap.ts";
import * as $$$4 from "./loaders/cart.ts";
import * as $$$0 from "./loaders/ProductDetailsPage.ts";
Expand Down Expand Up @@ -35,6 +36,7 @@ const manifest = {
"shopify/actions/cart/updateItems.ts": $$$$$$$$$2,
"shopify/actions/order/draftOrderCalculate.ts": $$$$$$$$$3,
"shopify/actions/user/signIn.ts": $$$$$$$$$4,
"shopify/actions/user/signUp.ts": $$$$$$$$$5,
},
"name": "shopify",
"baseUrl": import.meta.url,
Expand Down
26 changes: 26 additions & 0 deletions shopify/utils/storefront/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,32 @@ export const AddItemToCart = {
}`,
};

export const RegisterAccount = {
query: gql`mutation RegisterAccount(
$email: String!,
$password: String!,
$firstName: String,
$lastName: String,
$acceptsMarketing: Boolean = false
) {
customerCreate(input: {
email: $email,
password: $password,
firstName: $firstName,
lastName: $lastName,
acceptsMarketing: $acceptsMarketing,
}) {
customer {
id
}
customerUserErrors {
code
message
}
}
}`,
};

export const AddCoupon = {
fragments: [Cart],
query: gql`mutation AddCoupon($cartId: ID!, $discountCodes: [String!]!) {
Expand Down

0 comments on commit 8fd0f4e

Please sign in to comment.