"Cancel" buttons replaced with <Link>
This commit is contained in:
@@ -8,11 +8,16 @@ import { useFormState } from "react-dom";
|
||||
import Link from "next/link";
|
||||
import { gotoHome } from "../lib/actions/navigationActions";
|
||||
|
||||
export interface LocationEditFormProps {
|
||||
export type LocationEditFormProps = {
|
||||
/** location which should be edited */
|
||||
location?: BillingLocation,
|
||||
location: BillingLocation,
|
||||
/** year adn month at a new billing location should be assigned */
|
||||
yearMonth?: YearMonth
|
||||
yearMonth: undefined
|
||||
} | {
|
||||
/** location which should be edited */
|
||||
location: undefined,
|
||||
/** year adn month at a new billing location should be assigned */
|
||||
yearMonth: YearMonth
|
||||
}
|
||||
|
||||
export const LocationEditForm:FC<LocationEditFormProps> = ({ location, yearMonth }) =>
|
||||
@@ -21,14 +26,7 @@ export const LocationEditForm:FC<LocationEditFormProps> = ({ location, yearMonth
|
||||
const handleAction = updateOrAddLocation.bind(null, location?._id, yearMonth);
|
||||
const [ state, dispatch ] = useFormState(handleAction, initialState);
|
||||
|
||||
// redirect to the main page
|
||||
const handleCancel = () => {
|
||||
if(location)
|
||||
gotoHome(location?.yearMonth);
|
||||
else if(yearMonth)
|
||||
gotoHome(yearMonth);
|
||||
|
||||
};
|
||||
let { year, month } = location ? location.yearMonth : yearMonth;
|
||||
|
||||
return(
|
||||
<div className="card card-compact card-bordered min-w-[20em] max-w-[90em] bg-base-100 shadow-s my-1">
|
||||
@@ -71,7 +69,7 @@ export const LocationEditForm:FC<LocationEditFormProps> = ({ location, yearMonth
|
||||
|
||||
<div className="pt-4">
|
||||
<button className="btn btn-primary">Save</button>
|
||||
<button type="button" className="btn btn-neutral ml-3" onClick={handleCancel}>Cancel</button>
|
||||
<Link className="btn btn-neutral ml-3" href={`/?year=${year}&month=${month}`}>Cancel</Link>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -86,10 +84,6 @@ export const LocationEditFormSkeleton:FC = () =>
|
||||
<div className="card-body">
|
||||
<input id="locationName" name="locationName" type="text" placeholder="Naziv lokacije" className="input input-bordered w-full" />
|
||||
<textarea id="locationNotes" name="locationNotes" className="textarea textarea-bordered my-1 w-full block" placeholder="Opis"></textarea>
|
||||
<div className="pt-4">
|
||||
<button className="btn btn-primary">Save</button>
|
||||
<button type="button" className="btn btn-neutral ml-3">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user