-
Notifications
You must be signed in to change notification settings - Fork 14
Updates organization creation page #620
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,108 @@ | ||
| <script lang="ts"> | ||
| import type { Organization } from "@/types"; | ||
|
|
||
| import TeamListItem from "./TeamListItem.svelte"; | ||
|
|
||
| let results: Organization[] = $state([]); | ||
| let searched = $state(false); | ||
| let timeout: ReturnType<typeof setTimeout> | undefined; | ||
|
|
||
| function onInput(event: Event) { | ||
| const query = (event.target as HTMLInputElement).value.trim(); | ||
| clearTimeout(timeout); | ||
|
|
||
| if (query.length < 2) { | ||
| results = []; | ||
| searched = false; | ||
| return; | ||
| } | ||
|
|
||
| timeout = setTimeout(async () => { | ||
| const url = `/fe_api/organizations/?individual=false&search=${encodeURIComponent(query)}&fuzzy=true`; | ||
| try { | ||
| const resp = await fetch(url, { credentials: "include" }); | ||
| const data = await resp.json(); | ||
| results = data.results ?? []; | ||
| } catch { | ||
| results = []; | ||
| } | ||
| searched = true; | ||
| }, 500); | ||
| } | ||
|
|
||
| // Find the name input and attach the listener | ||
| $effect(() => { | ||
| const input = document.querySelector<HTMLInputElement>('input[name="name"]'); | ||
| if (input) { | ||
| input.addEventListener("input", onInput); | ||
| return () => input.removeEventListener("input", onInput); | ||
| } | ||
| }); | ||
| </script> | ||
|
|
||
| {#if results.length > 0} | ||
| <div class="card"> | ||
| <p class="heading">It looks like {results.length > 1 ? 'organizations with similar names are' : 'an organization with a similar name is'} already up and running on MuckRock:</p> | ||
| <ul class="results"> | ||
| {#each results as org (org.id)} | ||
| <li> | ||
| <a href="/organizations/{org.slug}/" target="_blank" rel="noopener"> | ||
| <TeamListItem organization={org} /> | ||
| </a> | ||
| </li> | ||
| {/each} | ||
| </ul> | ||
| <p> | ||
| If the organization you're trying to create is already set up on MuckRock, please look for the <b>Request to Join</b> option on the organization's profile page. Please <a href="mailto:info@muckrock.com">contact support</a> if the admins listed have left the organization. | ||
| </p> | ||
| </div> | ||
| {:else if searched} | ||
| <p class="hint">No similarly named organizations found.</p> | ||
| {:else} | ||
| <p class="hint">To discourage duplicate organizations, any existing organizations with similar names will appear here.</p> | ||
| {/if} | ||
|
|
||
| <style> | ||
| .card { | ||
| padding: 1rem; | ||
| color: var(--gray-5); | ||
| } | ||
|
|
||
| .hint { | ||
| width: 100%; | ||
| color: var(--gray-4); | ||
| border: 1px solid var(--gray-2); | ||
| border-radius: 8px; | ||
| padding: 1rem; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| p { | ||
| margin: 0; | ||
| } | ||
|
|
||
| .heading { | ||
| font-weight: 600; | ||
| } | ||
|
|
||
| .results { | ||
| list-style: none; | ||
| padding: 0; | ||
| margin: 1rem 0; | ||
| } | ||
|
|
||
| .results li { | ||
| margin-bottom: 0.5rem; | ||
| } | ||
|
|
||
| .results a { | ||
| text-decoration: none; | ||
| color: inherit; | ||
| display: block; | ||
| } | ||
|
|
||
| .results a:hover { | ||
| background: var(--color-surface-hover, #f5f5f5); | ||
| border-radius: 4px; | ||
| } | ||
| </style> | ||
This file contains hidden or 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,27 @@ | ||
| .create-organization { | ||
| max-width: 32rem; | ||
| min-height: 50vh; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 2rem; | ||
| padding: 4rem 2rem; | ||
| } | ||
|
|
||
| .create-organization h1, h2 { | ||
| margin: 0; | ||
| } | ||
|
|
||
| .unverified { | ||
| gap: 1rem; | ||
| } | ||
|
|
||
| .unverified p { | ||
| color: var(--gray-4); | ||
| } | ||
|
|
||
| form { | ||
| width: 100%; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 1rem; | ||
| } |
This file contains hidden or 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,12 @@ | ||
| import "@/css/team_list_item.css"; | ||
| import "@/css/organization_create.css"; | ||
|
|
||
| import { mount } from "svelte"; | ||
| import OrgNameSearch from "../components/OrgNameSearch.svelte"; | ||
|
|
||
| window.addEventListener("DOMContentLoaded", () => { | ||
| const el = document.getElementById("org_name_search"); | ||
| if (el) { | ||
| mount(OrgNameSearch, { target: el }); | ||
| } | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels brittle. If we change the input name, it's going to break, and it's hard to follow the code.
I realize this is separate from the form, so it's tricky to tie them together.
We could take an input element as a prop, and that would at least guarantee we have an input.
We do have a test that looks for
input[name='name'], so that's something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very valid. I do have confidence the input name won't change since it's tied to the model: this maps to the
namefield ofOrganization, which will probably never change? I think the test is a good guarantee of the stability here—if we're renaming this fundamental model field, this (and many other) tests will fail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's reasonable. As long as we feel confident we'll catch anything that breaks, we should be ok.