-
Notifications
You must be signed in to change notification settings - Fork 2
Add handling for contractor applications #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This looks good. I'm happy with this if you can clean up the type errors. I tested it locally and it worked
I agree on the confirmation page. Will create a ticket for that.
@@ -61,3 +65,51 @@ export const getContractors = async (page = 1, pageSize = 10) => { | |||
throw new Error("Failed to fetch contractors"); | |||
} | |||
}; | |||
|
|||
export async function createContractor(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this'll fix the typescript error -- I haven't tried it -- but it'd be my first attempt.
Also -- the createContractor
function would be a helpful constructor to have on the Contractor data model instead of a helper method here. Just a suggestion. You don't have to do it in this PR
export async function createContractor(data) { | |
export async function createContractor(contractor: Contractor) { |
@@ -1,6 +1,7 @@ | |||
import { MetaFunction, ActionFunctionArgs, redirect } from "@remix-run/node"; | |||
import { Form, useActionData } from "@remix-run/react"; | |||
import React, { useState, Dispatch, SetStateAction } from "react"; | |||
import { createContractor } from "~/models/contractor.server"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running npm run lint:fix
should fix this error and any other auto-fixable lint errors
@@ -502,25 +506,40 @@ export async function action({ request }: ActionFunctionArgs) { | |||
errors.website = "Please provide a valid website URL."; | |||
} | |||
|
|||
let statesServed = null; | |||
let statesServed: Array<String> = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let statesServed: Array<String> = []; | |
let statesServed: string[] = []; |
errors.statesServed = "Please select at least one state."; | ||
} | ||
|
||
let services = null; | ||
let services: Array<String> = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let services: Array<String> = []; | |
let services: string[] = []; |
@@ -48,5 +49,37 @@ describe("smoke tests", () => { | |||
|
|||
cy.findByText("No notes yet"); | |||
}); | |||
|
|||
it.skip("should allow contractors to request to be listed", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Feel free to unskip this if it passes
I know it's not great but we just haven't been writing tests. The timeline is so short that we've just been aiming to get it working and then flesh out tests after May 10th.
try { | ||
const statesServed = [] | ||
for (const stateName of data["statesServed"]) { | ||
const state: State = await prisma.state.findFirst({where: {name: stateName}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using findFirstOrThrow
here and for services and certifications, so you don't have to check for null yourself
const state: State = await prisma.state.findFirst({where: {name: stateName}}); | |
const state = await prisma.state.findFirstOrThrow({where: {name: stateName}}); |
} | ||
}); | ||
} catch (error) { | ||
console.log("Error creating contractor", error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log("Error creating contractor", error); | |
console.error("Error creating contractor", error); |
Oh, also, you can check for lint failures with |
Draft PR.
I have added the model code needed to create new contractor listings along with
isDraft
set to1
.I need some guidance on adding tests (seems like current smoke tests are skipped). Also we should probably add some kind of a confirmation page which tells the user their application was submitted and under review.
I am typescript newbie so I am not sure if I should be using a type for api request payloads right now it's a regular js object which generates a warning in vscode.