forked from funmusicplace/mirlo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request funmusicplace#805 from funmusicplace/various-fixes
feat: punt license feature
- Loading branch information
Showing
25 changed files
with
414 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { css } from "@emotion/css"; | ||
|
||
import LicenseForm from "components/common/LicenseForm"; | ||
import Modal from "components/common/Modal"; | ||
import Table from "components/common/Table"; | ||
import React from "react"; | ||
import { Outlet, useNavigate } from "react-router-dom"; | ||
import api from "services/api"; | ||
|
||
export const AdminLicenses: React.FC = () => { | ||
const navigate = useNavigate(); | ||
const [results, setResults] = React.useState<License[]>([]); | ||
const [openModal, setOpenModal] = React.useState(false); | ||
|
||
const callback = React.useCallback(async () => { | ||
const { results } = await api.getMany<License>("licenses"); | ||
setResults(results); | ||
}, []); | ||
|
||
React.useEffect(() => { | ||
callback(); | ||
}, []); | ||
|
||
return ( | ||
<div | ||
className={css` | ||
flex-grow: 1; | ||
`} | ||
> | ||
<h3>Licenses</h3> | ||
<LicenseForm callback={callback} /> | ||
{results.length > 0 && ( | ||
<Table> | ||
<thead> | ||
<tr> | ||
<th /> | ||
<th>Short</th> | ||
<th>URL</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{results.map((license, index) => ( | ||
<tr key={license.short}> | ||
<td>{index + 1}</td> | ||
|
||
<td>{license.short}</td> | ||
<td>{license.link}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
)} | ||
{/* <LoadingButton /> */} | ||
<Modal | ||
open={openModal} | ||
onClose={() => { | ||
setOpenModal(false); | ||
navigate("/admin/trackgroups"); | ||
}} | ||
> | ||
<Outlet /> | ||
</Modal> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AdminLicenses; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useFormContext } from "react-hook-form"; | ||
import { SelectEl } from "components/common/Select"; | ||
import { queryLicenses } from "queries/licenses"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import FormComponent from "components/common/FormComponent"; | ||
import { useTranslation } from "react-i18next"; | ||
import Button from "components/common/Button"; | ||
import { css } from "@emotion/css"; | ||
import Modal from "components/common/Modal"; | ||
import React from "react"; | ||
import LicenseForm from "components/common/LicenseForm"; | ||
|
||
const ManageTrackLicense = () => { | ||
const [isModalOpen, setIsModalOpen] = React.useState(false); | ||
const { t } = useTranslation("translation", { keyPrefix: "manageAlbum" }); | ||
const methods = useFormContext(); | ||
|
||
const { data: licenses, refetch } = useQuery(queryLicenses()); | ||
|
||
return ( | ||
<> | ||
<Modal | ||
open={isModalOpen} | ||
onClose={() => setIsModalOpen(false)} | ||
title={t("addALicense")} | ||
> | ||
<LicenseForm callback={refetch} /> | ||
</Modal> | ||
<FormComponent> | ||
<label>{t("license")}</label> | ||
<SelectEl {...methods.register("licenseId")}> | ||
{licenses?.results.map((license) => ( | ||
<option value={license.id}>{license.short}</option> | ||
))} | ||
</SelectEl> | ||
<small | ||
className={css` | ||
display: flex; | ||
align-items: center; | ||
`} | ||
> | ||
{t("dontSeeTheLicenseYouWant")} | ||
<Button | ||
variant="dashed" | ||
onClick={() => setIsModalOpen(true)} | ||
type="button" | ||
compact | ||
className={css` | ||
margin-left: 0.25rem; | ||
`} | ||
> | ||
{t("addIt")} | ||
</Button> | ||
</small> | ||
<small>{t("whatMeanLicense")}</small> | ||
</FormComponent> | ||
</> | ||
); | ||
}; | ||
|
||
export default ManageTrackLicense; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from "react"; | ||
import Button from "./Button"; | ||
import { InputEl } from "./Input"; | ||
import { useForm } from "react-hook-form"; | ||
import api from "services/api"; | ||
import useErrorHandler from "services/useErrorHandler"; | ||
import FormComponent from "./FormComponent"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
interface FormData { | ||
short: string; | ||
link?: string; | ||
name: string; | ||
} | ||
|
||
const LicenseForm: React.FC<{ callback: () => void }> = ({ callback }) => { | ||
const methods = useForm<FormData>(); | ||
const errorHandler = useErrorHandler(); | ||
const { t } = useTranslation("translation", { keyPrefix: "manageLicense" }); | ||
|
||
const onSubmit = React.useCallback(async (data: FormData) => { | ||
try { | ||
await api.post(`licenses`, data); | ||
await callback(); | ||
} catch (e) { | ||
errorHandler(e); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<form onSubmit={methods.handleSubmit(onSubmit)}> | ||
<FormComponent> | ||
<label>{t("shortLabelForLicense")}</label> | ||
<InputEl | ||
{...methods.register("short")} | ||
placeholder={t("egShort") ?? ""} | ||
/>{" "} | ||
</FormComponent> | ||
<FormComponent> | ||
<label>{t("longLabel")}</label> | ||
<InputEl | ||
{...methods.register("name")} | ||
placeholder={t("egLong") ?? ""} | ||
/>{" "} | ||
</FormComponent> | ||
<FormComponent> | ||
<label>{t("urlForLabel")}</label> | ||
<InputEl | ||
{...methods.register("link")} | ||
placeholder={t("egLink") ?? ""} | ||
/>{" "} | ||
</FormComponent> | ||
<Button>{"add"}</Button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default LicenseForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { QueryFunction, queryOptions } from "@tanstack/react-query"; | ||
import * as api from "./fetch/fetchWrapper"; | ||
import { QUERY_KEY_TAGS } from "./queryKeys"; | ||
|
||
const fetchLicenses: QueryFunction< | ||
{ results: License[]; total?: number }, | ||
["fetchLicenses", ...any] | ||
> = ({ queryKey: [_, {}], signal }) => { | ||
const params = new URLSearchParams(); | ||
|
||
return api.get(`v1/licenses?${params}`, { signal }); | ||
}; | ||
|
||
export function queryLicenses() { | ||
return queryOptions({ | ||
queryKey: ["fetchLicenses", {}, QUERY_KEY_TAGS], | ||
queryFn: fetchLicenses, | ||
}); | ||
} |
Oops, something went wrong.