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

Issue 198 repair attempt full screen modal #232

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3177cf3
cleaned up repair request form
AarifLamat Feb 5, 2024
ac77850
made checkbox bigger
AarifLamat Feb 6, 2024
e075202
pulled from main
AarifLamat Feb 10, 2024
c84e063
edited field components to allow page bg colour, moved repairAttemptF…
AarifLamat Feb 14, 2024
d33d5f4
allowed fields to be prepopulated, added properties to components to …
AarifLamat Feb 15, 2024
4145d70
Merge branch 'main' of https://github.com/codersforcauses/repair-labs…
AarifLamat Feb 15, 2024
831dec5
ran prettier
AarifLamat Feb 15, 2024
603f8c1
added overflow to modal, yPosition to box label and size adjustment t…
AarifLamat Feb 17, 2024
29c068e
Merge branch 'main' of https://github.com/codersforcauses/repair-labs…
AarifLamat Feb 17, 2024
d932c50
spare parts is defaulted to nothing instead of no
AarifLamat Feb 17, 2024
20aee39
padding
AarifLamat Feb 17, 2024
1fc72b1
fixed repair attempt submission to use repair id rather than event id
AarifLamat Feb 17, 2024
e4d1c25
cleaned up repair attempt form
AarifLamat Feb 19, 2024
4901e48
updated looks a bit innit
AarifLamat Feb 21, 2024
48e8c10
Merge branch 'main' of https://github.com/codersforcauses/repair-labs…
AarifLamat Feb 21, 2024
cec63c8
made form a tad shorter at different heights so the cross is always v…
AarifLamat Feb 21, 2024
513f656
Merge branch 'main' of https://github.com/codersforcauses/repair-labs…
AarifLamat Feb 24, 2024
431c634
yeye pulled from origin
AarifLamat Feb 24, 2024
5302ec8
changed screated by to display name instead of id
AarifLamat Feb 24, 2024
652360a
deleted redundant 'fake repair attempt form'
AarifLamat Feb 24, 2024
07594c6
cleaned up some code
AarifLamat Feb 24, 2024
6622ed3
placed repair comment and parts in a div so submit button doesnt move
AarifLamat Feb 24, 2024
8f41f88
removed unnecessary comments
AarifLamat Mar 8, 2024
bf41bf4
tiny responsive changes
AarifLamat Mar 22, 2024
5d5936b
Merge branch 'main' of https://github.com/codersforcauses/repair-labs…
AarifLamat Mar 22, 2024
f0085fe
ran npm i
AarifLamat Mar 22, 2024
04dff94
Merge branch 'main' of https://github.com/codersforcauses/repair-labs…
AarifLamat Jun 2, 2024
5cc3f2f
modal is w-full on mobile, still doesn't take full screen as it uses …
AarifLamat Jun 13, 2024
b3a81a1
fixed type errors hopefully
AarifLamat Jun 13, 2024
8a6ab6e
see prev
AarifLamat Jun 13, 2024
b505da0
styling on navbar and landing page
AarifLamat Nov 4, 2024
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
510 changes: 291 additions & 219 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
textSize?: string;
hover?: string;
position?: string;
textWeight?: string;
}

export default function Button({
Expand All @@ -22,13 +23,14 @@ export default function Button({
textSize = "text-lg",
hover = "hover:bg-primary-800",
position = "mx-auto",
textWeight = "font-normal",
children,
...props
}: ButtonProps) {
return (
<button
{...props}
className={`${color} ${border} ${radius} ${height} ${width} ${textColor} ${textSize} ${hover} ${position}`}
className={`${color} ${border} ${radius} ${height} ${width} ${textColor} ${textSize} ${hover} ${position} ${textWeight}`}
>
{children}
</button>
Expand Down
79 changes: 70 additions & 9 deletions src/components/EventBox/request-view.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { useCallback, useEffect, useState } from "react";
import { Disclosure, Transition } from "@headlessui/react";
import { FaChevronDown } from "react-icons/fa6";

import { User } from "@/types";
import RepairAttemptForm from "@/components/Forms/repair-attempt-form";
import Modal from "@/components/Modal";
import { RepairRequestResponse, User } from "@/types";

// Contains type of info stored in our event box.
type RequestProps = {
export type RequestProps = {
repairRequestId: number;
createdBy: User;
requestDate: string;
itemType: string;
itemBrand: string;
description: string;
handleClick?: () => void;
repairAttemptProps: RepairRequestResponse;
};

const RequestView = ({
Expand All @@ -20,8 +23,54 @@
requestDate,
itemType,
itemBrand,
description
description,
repairAttemptProps
}: RequestProps) => {
const [showRepairRequestModal, setShowRepairRequestModal] = useState(false);
// function manageModal() {
// setShowRepairRequestModal(true);
// }

const useWindowDimensions = () => {
const hasWindow = typeof window !== "undefined";

const getWindowDimensions = useCallback(() => {
const width = hasWindow ? window.innerWidth : null;
const height = hasWindow ? window.innerHeight : null;
return {
width,
height
};
}, [hasWindow]);

const [windowDimensions, setWindowDimensions] = useState(
getWindowDimensions()
);

useEffect(() => {
if (hasWindow) {
const handleResize = () => {
setWindowDimensions(getWindowDimensions());
};

window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}
}, [hasWindow, getWindowDimensions]);

return windowDimensions;
};

const { height, width } = useWindowDimensions();

Check warning on line 64 in src/components/EventBox/request-view.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'height' is assigned a value but never used. Allowed unused vars must match /^_/u

function handleRepairClick() {
if (width) {
width > 640
? setShowRepairRequestModal(true)
: setShowRepairRequestModal(false);
// this is for if we want to optionally render a seperate page on mobile view
}
}
return (
<div className="mx-5 mt-4 rounded-lg bg-slate-200 shadow-lg">
<Disclosure>
Expand All @@ -34,7 +83,7 @@
>
<div className=" flex flex-col text-left py-2">
<span className="font-bold">
{repairRequestId}- {createdBy.id}
{repairRequestId}- {createdBy.firstName} {createdBy.lastName}
</span>
</div>
<FaChevronDown
Expand Down Expand Up @@ -75,14 +124,26 @@
<div className="flex justify-center mt-1">
<button
className="bg-primary-700 px-4 py-1 rounded-lg text-white text-md hover:bg-primary-600"
// onClick={() =>
// For future use when linking to issue 198
// router.push("")
// }
onClick={handleRepairClick}
// onKeyDown={handleRepairClick}
>
Repair
</button>
</div>
<Modal
showModal={showRepairRequestModal}
setShowPopup={setShowRepairRequestModal}
height="h-full overflow-auto"
title="Repair Attempt"
width="w-full sm:w-full md:w-2/3 lg:w-1/2"
crossWidthAndHeight="w-10 h-10"
>
<div className="text-center">
<div>
<RepairAttemptForm props={repairAttemptProps} />
</div>
</div>
</Modal>
</Disclosure.Panel>
</Transition>
</>
Expand Down
6 changes: 5 additions & 1 deletion src/components/FormFields/box-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FieldValues, UseControllerProps } from "react-hook-form";
export interface FormProps<T extends FieldValues = FieldValues>
extends UseControllerProps<T> {
label?: string;
yPosition?: string;
}

/*
Expand All @@ -12,10 +13,13 @@ Output:
*/
export default function Label<T extends FieldValues = FieldValues>({
label,
yPosition = "-top-3",
...props
}: FormProps<T>) {
return (
<label className="absolute -top-2 left-2 flex flex-row items-center gap-0.5 rounded-full bg-white px-1 text-sm font-semibold text-black">
<label
className={`absolute ${yPosition} left-2 flex flex-row items-center gap-0.5 rounded-full bg-white px-1 text-s font-semibold text-black`}
>
{label}
{props.rules?.required ? (
<span className="text-sm font-semibold text-red-500"> *</span>
Expand Down
5 changes: 3 additions & 2 deletions src/components/FormFields/field-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface FormProps<T extends FieldValues = FieldValues>
icon?: string | ReactElement;
type?: string;
width?: string;
height?: string;
}

/*
Expand All @@ -38,11 +39,11 @@ export default function FieldInput<T extends FieldValues = FieldValues>({
icon,
type,
width = "w-full",
height = "min-h-10",
...props
}: FormProps<T>) {
const { field, fieldState } = useController(props);

const baseStyle = `relative mb-2 flex h-12 ${width} flex-row items-center justify-between rounded-lg border px-3 shadow hover:shadow-grey-300`;
const baseStyle = `relative flex ${width} ${height} mb-2 justify-between rounded-lg bg-white px-3 py-2.5 text-sm font-medium text-gray-900 border shadow-sm hover:shadow-grey-300`;
const errorBorderStyle = `border-red-500`;
const normalBorderStyle = `border-grey-300`;
const inputStyle = `mr-1 w-full h-full text-base placeholder:text-gray-500 focus:outline-none focus:ring-0`;
Expand Down
17 changes: 13 additions & 4 deletions src/components/FormFields/field-radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export interface FormProps<T extends FieldValues = FieldValues>
id?: string;
label?: string;
width?: string;
height?: string;
axis?: string;
labelYPosition?: string;
}

/*
Expand All @@ -28,22 +31,28 @@ export default function FieldRadio<T extends FieldValues = FieldValues>({
id,
label,
width = "w-full",
height = "min-h-10",
axis = "flex-row",
labelYPosition = "-top-3",
...props
}: FormProps<T>) {
const { field, fieldState } = useController(props);

const baseStyle = `relative mb-2 flex h-10 ${width} flex-row items-center justify-between rounded-lg border px-3 shadow hover:shadow-grey-300`;
const baseStyle = `relative flex ${width} ${height} mb-2 items-center justify-between rounded-lg bg-white px-3 py-2.5 text-sm font-medium text-gray-900 border shadow-sm hover:shadow-grey-300`;
const errorBorderStyle = `border-red-500`;
const normalBorderStyle = `border-grey-300`;
const radioStyle = `my-auto flex flex-row items-start gap-4 text-xs`;
const radioStyle = `m-auto flex ${axis} items-start gap-4 text-xs justify-center`;

return (
<div
className={`${baseStyle} ${
fieldState.invalid ? `${errorBorderStyle}` : `${normalBorderStyle}`
}`}
>
<Label label={!label ? props.name : label} {...props} />
<Label
label={!label ? props.name : label}
yPosition={`${labelYPosition}`}
{...props}
/>
<div className={radioStyle}>
<label htmlFor={`${props.name}-y`} className="flex gap-1">
<input
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormFields/field-text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function FieldTextArea<T extends FieldValues = FieldValues>({
}: FormProps<T>) {
const { field, fieldState } = useController(props);

const baseStyle = `relative mb-2 flex ${height} ${width} flex-row items-center justify-between rounded-lg border border-grey-300 px-3 shadow hover:shadow-grey-300`;
const baseStyle = `relative flex ${height} ${width} justify-between rounded-lg bg-white px-3 py-2.5 text-base font-medium text-gray-900 shadow-sm border border-grey-300 hover:shadow-grey-300`;
const errorBorderStyle = `border-red-500`;
const normalBorderStyle = `border-grey-300`;
const textAreaStyle = `overflow-wrap:break-word pt-3 h-full w-full resize-none overflow-y-auto text-base placeholder:text-gray-500 placeholder:font-normal focus:outline-none focus:ring-0`;
Expand Down
20 changes: 14 additions & 6 deletions src/components/Forms/create-repair-request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ export default function RepairRequestForm({ eventId }: { eventId?: string }) {
<FieldInput
name="itemBrand"
control={control}
placeholder="Select a brand"
placeholder="Select a brand..."
label="Brand"
rules={{ required: true }}
/>
<SingleSelect
name="itemType"
control={control}
placeholder="Select an item type"
placeholder="Select an item type..."
label="Item Type"
rules={{ required: true }}
options={
Expand All @@ -92,17 +92,19 @@ export default function RepairRequestForm({ eventId }: { eventId?: string }) {
<FieldTextArea
name="description"
label="Description"
placeholder="Enter a description"
placeholder="Enter a description..."
control={control}
rules={{ required: true }}
/>

<FieldImageUpload multiple name="images" control={control} />
<p className="text-center">(psst you can upload multiple images)</p>
{/* Input field for Event */}
{!eventId && (
<SingleSelect
name="eventId"
control={control}
placeholder="Select an event"
placeholder="Select an event..."
label="Event"
options={
eventOptions
Expand All @@ -116,12 +118,18 @@ export default function RepairRequestForm({ eventId }: { eventId?: string }) {
<FieldTextArea
name="comment"
label="Additional Comment"
placeholder="Enter additional comments"
placeholder="Anything else we should know?"
control={control}
rules={{ required: false }}
/>
<TermsAndConditions setValue={setValue} control={control} />
<Button type="submit" height="h-9" width="w-full" textSize="text-base">
<Button
type="submit"
height="h-12"
width="w-full"
textSize="text-lg"
textWeight="font-semibold"
>
Submit
</Button>
</form>
Expand Down
Loading
Loading