Skip to content
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

Hampus/fix/cr errors #909

Merged
merged 7 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/complete_registration/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ video {
height: 0.125rem;
}

.h-\[100vh\] {
height: 100vh;
}

.h-full {
height: 100%;
}
Expand Down Expand Up @@ -669,6 +673,10 @@ video {
width: 18rem;
}

.w-\[100vw\] {
width: 100vw;
}

.w-\[450px\] {
width: 450px;
}
Expand Down
23 changes: 12 additions & 11 deletions apps/complete_registration/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import { selectActiveForm } from "./store/form/form_selectors"
import { useEffect, useRef } from "react"
import { reverseMap } from "./utils/mapper"
import { useDispatch } from "react-redux"
import { setField } from "./store/form/form_slice"
import { setErrors, setField } from "./store/form/form_slice"
import {
PACKAGE_KEY,
ProductMeta,
loadProducts,
pickProduct
} from "./store/products/products_slice"
import { DashboardScreen } from "./screens/dashboard/screen"
import {
RegistrationStatus,
setCompanyName,
setCompanyRegistrationStatus,
setUser
} from "./store/company/company_slice"

export const HOST = ""
import { HOST, PACKAGE_KEY } from "./shared/vars"

export function App() {
const initialized = useRef(false)
Expand All @@ -33,19 +32,21 @@ export function App() {
const data = await raw.json()
dispatch(loadProducts(data))
})
fetch(`${HOST}/api/registration/`, {
headers: new Headers({
"ngrok-skip-browser-warning": "69420"
})
}).then(async raw => {
fetch(`${HOST}/api/registration/`, {}).then(async raw => {
const data = await raw.json()

if (data.error != null) {
dispatch(setErrors(data.error))
}

const awaitingMappings = reverseMap(data)

// Set status for company
dispatch(
setCompanyRegistrationStatus(data.type as RegistrationStatus)
)
dispatch(setUser(data.contact))
if (data.company?.name) dispatch(setCompanyName(data.company.name))
if (data.contact) dispatch(setUser(data.contact))

for (const current of awaitingMappings) {
dispatch(
Expand All @@ -58,7 +59,7 @@ export function App() {

// Apply orders
const orders = data.orders as ProductMeta[]
for (const productMeta of orders) {
for (const productMeta of orders ?? []) {
dispatch(
pickProduct({
id: productMeta.product.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
import { FormWrapper } from "../FormWrapper"
import { FormField } from "../../screens/form/FormInput"
import { CompleteButton } from "../../shared/CompleteButton"

export function DetailedFormPage() {
return (
<FormWrapper>
<FormField.MultiSelect
label=""
label="Your industries"
mapping="exhibitor.catalogue_industries"
options={[
{
label: "First",
value: "first"
},
{
label: "Second",
value: "third"
}
]}
className="w-full"
filter
optionLabel="industry"
optionValue="selected"
/>
<FormField.MultiSelect
label="What employment are you offering?"
mapping="exhibitor.catalogue_employments"
className="w-full"
filter
optionLabel="employment"
optionValue="selected"
/>
<FormField.MultiSelect
label="Select your countries"
mapping="exhibitor.catalogue_locations"
className="w-full"
filter
optionLabel="location"
optionValue="selected"
/>
<div className="mt-10 flex justify-center">
<CompleteButton />
</div>
</FormWrapper>
)
}
10 changes: 9 additions & 1 deletion apps/complete_registration/src/forms/exhibitor_catalog/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const form: Form = {
{
id: "logo",
title: "Logo",
hasNextButton: false,
pageComponent: LogoFormPage,
fields: [
{
Expand All @@ -51,10 +50,19 @@ export const form: Form = {
id: "detailed",
title: "Exhibitor Specification",
pageComponent: DetailedFormPage,
hasNextButton: false,
fields: [
{
mapping: "exhibitor.catalogue_industries",
isMultiSelect: true
},
{
mapping: "exhibitor.catalogue_employments",
isMultiSelect: true
},
{
mapping: "exhibitor.catalogue_locations",
isMultiSelect: true
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FormWrapper } from "../FormWrapper"
import { FormField } from "../../screens/form/FormInput"
import { CompleteButton } from "../../shared/CompleteButton"

export function LogoFormPage() {
return (
Expand All @@ -13,10 +12,6 @@ export function LogoFormPage() {
mapping="exhibitor.catalogue_logo_freesize"
label="Company Free Sized Logo"
/>

<div className="mt-10 flex flex-1 justify-center">
<CompleteButton />
</div>
</FormWrapper>
)
}
11 changes: 11 additions & 0 deletions apps/complete_registration/src/forms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ export function getMutableFormsInstance() {
}
}
export const FORMS = Object.freeze(getMutableFormsInstance())

export function getFieldFromForm(forms: typeof FORMS, mapping: string) {
// Iterate over all forms and pages to find the field with the given mapping
for (const formMeta of Object.values(forms)) {
for (const page of formMeta.pages) {
const field = page.fields?.find(f => f.mapping == mapping) ?? 0
if (field) return field
}
}
return null
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function PackageSelectFormPage() {
const packages = useSelector(selectProductPackages)

return (
<FormWrapper>
<FormWrapper className="max-w-none">
<div className="flex flex-wrap justify-center gap-5">
{packages.map(productPackageMeta => (
<FormField.Package
Expand Down
23 changes: 16 additions & 7 deletions apps/complete_registration/src/forms/primary/summary.page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button } from "primereact/button"
import { Checkbox } from "primereact/checkbox"
import { useState, MouseEvent } from "react"
import { useState, MouseEvent, useRef } from "react"
import { useDispatch, useSelector } from "react-redux"
import {
selectActiveForm,
Expand All @@ -9,48 +9,57 @@ import {
import { RootState } from "../../store/store"
import { Card } from "../../screens/form/sidebar/PageCard"
import { ConfirmPopup, confirmPopup } from "primereact/confirmpopup"
import { HOST } from "../../App"
import { setCompanyRegistrationStatus } from "../../store/company/company_slice"
import { setActiveForm } from "../../store/form/form_slice"
import { Toast } from "primereact/toast"
import { HOST } from "../../shared/vars"

export function SummaryFormPage() {
const dispatch = useDispatch()
const toastRef = useRef<Toast>(null)
const [confirmEligibility, setConfirmEligibility] = useState(false)

const activeForm = useSelector(selectActiveForm)
const unfilledFields = useSelector((state: RootState) =>
selectUnfilledFields(state, activeForm?.key ?? "primary")
)

console.log("HELLO", unfilledFields, activeForm?.key)

const readyToSign = confirmEligibility && unfilledFields.length === 0

async function submitRegistration() {
const response = await fetch(`${HOST}/api/registration/submit`, {
method: "POST"
})
if (response.status < 200 || response.status >= 300) {
toastRef.current?.show({
severity: "error",
summary: "Error",
detail: "We encountered an error while submitting, if the problem persists please contact us."
})
return
}

dispatch(setCompanyRegistrationStatus("complete_registration_signed"))
dispatch(setActiveForm(null))
console.log(JSON.stringify(await response.json()))
}

const confirm = (event: MouseEvent<HTMLButtonElement>) => {
confirmPopup({
target: event.currentTarget,
message: (
<div className="flex flex-col">
<p> </p>
<p>Lock your product selection</p>
</div>
),
icon: "pi pi-exclamation-triangle",
icon: "pi pi-info-circle",
accept: submitRegistration,
reject: () => {}
})
}

return (
<div className="flex flex-col items-center">
<Toast ref={toastRef} />
{unfilledFields.length > 0 && (
<h2 className="mb-2 text-lg text-red-400">
Missing information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function TransportSummaryFormPage() {
const transportTo = useSelector((state: RootState) =>
selectField(state, "exhibitor.transport_to")
)
console.log(transportFrom, transportTo)
return (
<FormWrapper>
<div className="flex flex-col gap-5">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useSelector } from "react-redux"
import { selectErrors } from "../../store/form/form_selectors"

const ERRORS = {
not_authorized: (
<p>
You are not logged in, you can{" "}
<a className="text-emerald-400 underline" href="/register">
sign in here
</a>
</p>
),
user_did_not_sign_ir: (
<p>
You have not completed Initial Registraion please contact sales at{" "}
<span className="underline">[email protected]</span>
</p>
),
user_is_not_exhibitor: (
<p>
You did not get picked for the fair this year, contact
[email protected] if you have any questions
</p>
),
user_has_no_company: <p>You are not associated with any company</p>
}

export function DashboardError() {
const error = useSelector(selectErrors)

if (typeof error !== "string") return null

return (
<div className="flex h-[100vh] w-[100vw] flex-col items-center justify-center">
<p className="mb-4 text-4xl">Oups, something went wrong</p>
<div className="max-w-xl text-center">{ERRORS[error]}</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function FormCard({
<p className="text-xs text-slate-500">{form.description}</p>
<div className="flex-1" />
{form.key === "primary" && !locked && (
<p className="mt-2 rounded bg-yellow-500 p-1 px-3 text-white">
<p className="mt-4 rounded bg-yellow-500 p-1 px-3 text-white">
Contract has not been signed
</p>
)}
Expand Down
Loading
Loading