|
| 1 | +/* |
| 2 | + * @flow strict-local |
| 3 | + * Copyright (C) 2021 MetaBrainz Foundation |
| 4 | + * |
| 5 | + * This file is part of MusicBrainz, the open internet music database, |
| 6 | + * and is licensed under the GPL version 2, or (at your option) any |
| 7 | + * later version: http://www.gnu.org/licenses/gpl-2.0.txt |
| 8 | + */ |
| 9 | + |
| 10 | +import * as React from 'react'; |
| 11 | + |
| 12 | +import FormRowCheckbox from '../components/FormRowCheckbox'; |
| 13 | +import FormRowText from '../components/FormRowText'; |
| 14 | +import FormSubmit from '../components/FormSubmit'; |
| 15 | +import Layout from '../layout'; |
| 16 | +import expand2react from '../static/scripts/common/i18n/expand2react'; |
| 17 | + |
| 18 | +type Props = { |
| 19 | + +form: FormT<{ |
| 20 | + +use_regular_expression: ReadOnlyFieldT<boolean>, |
| 21 | + +username: ReadOnlyFieldT<string>, |
| 22 | + }>, |
| 23 | + +results?: $ReadOnlyArray<string>, |
| 24 | + +showResults: boolean, |
| 25 | +}; |
| 26 | + |
| 27 | +const LockedUsernameSearch = ({ |
| 28 | + form, |
| 29 | + results, |
| 30 | + showResults, |
| 31 | +}: Props): React.Element<typeof Layout> => ( |
| 32 | + <Layout fullWidth title="Search locked usernames"> |
| 33 | + <div id="content"> |
| 34 | + <h1>{'Search locked usernames'}</h1> |
| 35 | + |
| 36 | + <form action="/admin/locked-usernames/search" method="post"> |
| 37 | + <p> |
| 38 | + {expand2react( |
| 39 | + 'Enter a username or a {link|POSIX regular expression}.', |
| 40 | + { |
| 41 | + link: 'https://www.postgresql.org/docs/12/' + |
| 42 | + 'functions-matching.html#FUNCTIONS-POSIX-REGEXP', |
| 43 | + }, |
| 44 | + )} |
| 45 | + </p> |
| 46 | + |
| 47 | + <FormRowText |
| 48 | + field={form.field.username} |
| 49 | + label="Username:" |
| 50 | + size={50} |
| 51 | + uncontrolled |
| 52 | + /> |
| 53 | + |
| 54 | + <FormRowCheckbox |
| 55 | + field={form.field.use_regular_expression} |
| 56 | + label="Search using regular expression" |
| 57 | + uncontrolled |
| 58 | + /> |
| 59 | + |
| 60 | + <div className="row no-label"> |
| 61 | + <FormSubmit |
| 62 | + label="Search" |
| 63 | + name="lockedusernamesearch.submit" |
| 64 | + value="1" |
| 65 | + /> |
| 66 | + </div> |
| 67 | + |
| 68 | + {showResults ? ( |
| 69 | + <> |
| 70 | + <h3>{'Matching locked names:'}</h3> |
| 71 | + {results?.length ? ( |
| 72 | + <ul> |
| 73 | + {results.map(result => ( |
| 74 | + <li key={result}>{result}</li> |
| 75 | + ))} |
| 76 | + </ul> |
| 77 | + ) : ( |
| 78 | + <p> |
| 79 | + {'No locked usernames matched your search.'} |
| 80 | + </p> |
| 81 | + )} |
| 82 | + </> |
| 83 | + ) : null} |
| 84 | + </form> |
| 85 | + </div> |
| 86 | + </Layout> |
| 87 | +); |
| 88 | + |
| 89 | +export default LockedUsernameSearch; |
0 commit comments