Skip to content
Open
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
36 changes: 17 additions & 19 deletions client/src/pages/CreateProj.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components';
import React, { useState } from 'react';
import React, { PropsWithChildren, useState } from 'react';
import { toast } from 'react-hot-toast';
import { Form, useNavigate } from 'react-router-dom';
import { useUser } from '@clerk/clerk-react';
Expand Down Expand Up @@ -171,13 +171,14 @@ export function InputsView({
form,
onChange,
isFormValid,
loading
}: {
loading,
children
}: PropsWithChildren<{
form: FormState;
onChange: FormChangeHandler;
isFormValid: () => boolean;
loading: boolean;
}) {
}>) {
const onRadioChange = ({ target }: React.ChangeEvent<HTMLInputElement>) => {
if (target.checked) {
onChange(target.name as keyof FormState, target.value);
Expand Down Expand Up @@ -283,7 +284,9 @@ export function InputsView({
/>
</Input>

<SubmitBtnView isFormValid={isFormValid} desktop loading={loading} />
<SubmitBtnView isFormValid={isFormValid} desktop loading={loading}>
{children}
</SubmitBtnView>
</div>
);
}
Expand Down Expand Up @@ -366,19 +369,21 @@ function SubmitBtnView({
isFormValid,
desktop,
loading,
}: {
children
}: PropsWithChildren<{
isFormValid: () => boolean;
desktop: boolean;
loading: boolean;
}) {
}>) {
return (
<SubmitWrapper $desktop={desktop}>
{children}
<button
//disabled while form is invalid. Changes to loading spinner when pressed.
type="submit"
disabled={!isFormValid()}
aria-busy={loading}
className="group relative flex items-center justify-center bg-blue-500 text-zinc-100 cursor-pointer py-2 px-4 rounded-3xl transition-all hover:bg-blue-600 hover:shadow-md disabled:bg-blue-300 disabled:pointer-events-none min-w-[8rem] aria-busy:bg-blue-300 aria-busy:pointer-events-none"
className="group relative flex items-center justify-center bg-blue-500 text-zinc-100 cursor-pointer py-2 px-4 rounded-3xl transition-all hover:bg-blue-600 hover:shadow-md disabled:bg-blue-300 disabled:pointer-events-none min-w-[8rem] aria-busy:bg-blue-300 aria-busy:pointer-events-none self-end"
>
<p className="text-lg font-medium group-aria-busy:opacity-0">
Create Project
Expand All @@ -395,17 +400,10 @@ function SubmitBtnView({
}

const SubmitWrapper = styled.div<{ $desktop?: boolean }>`
width: 100%;
display: flex;
align-items: flex-end;
justify-content: flex-end;
display: ${props => props.$desktop ? 'none' : 'default'};
@media (min-width: 62rem) {
display: inline-block;
display: ${props => props.$desktop ? 'flex' : 'none'};
justify-content: flex-end;
align-items: flex-end;
}
display: inline-block;
display: ${props => props.$desktop ? 'flex' : 'none'};
justify-content: space-between;
align-items: center;
`;

const Image = styled.div`
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/EditProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ export function EditProject() {
onChange={updateForm}
isFormValid={isFormValid}
loading={projMutation.isLoading}
/>
>
<button onClick={() => console.log(formState)}>Check Form State</button>
</InputsView>
<input type="hidden" name="ownerId" value={user?.id} />
{/* Submit button for mobile view */}
<button onClick={() => console.log(formState)}> Check Form State</button>
</Form>
);
}