|
| 1 | +import { Form } from "react-router"; |
| 2 | +import type { GuildRole, ProcessedChannel } from "#~/helpers/guildData.server"; |
| 3 | + |
| 4 | +export function GuildSettingsForm({ |
| 5 | + guildId, |
| 6 | + roles, |
| 7 | + channels, |
| 8 | + buttonText = "Complete Setup", |
| 9 | + defaultValues, |
| 10 | +}: { |
| 11 | + guildId: string; |
| 12 | + roles: GuildRole[]; |
| 13 | + channels: ProcessedChannel[]; |
| 14 | + buttonText?: string; |
| 15 | + defaultValues?: { |
| 16 | + moderatorRole?: string; |
| 17 | + modLogChannel?: string; |
| 18 | + restrictedRole?: string; |
| 19 | + }; |
| 20 | +}) { |
| 21 | + return ( |
| 22 | + <Form method="post" className="space-y-6"> |
| 23 | + <input type="hidden" name="guild_id" value={guildId} /> |
| 24 | + |
| 25 | + <div> |
| 26 | + <label |
| 27 | + htmlFor="moderator_role" |
| 28 | + className="block text-sm font-medium text-gray-700" |
| 29 | + > |
| 30 | + Moderator Role <span className="text-red-500">*</span> |
| 31 | + </label> |
| 32 | + <div className="mt-1"> |
| 33 | + <select |
| 34 | + id="moderator_role" |
| 35 | + name="moderator_role" |
| 36 | + required |
| 37 | + defaultValue={defaultValues?.moderatorRole || ""} |
| 38 | + className="block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 text-black shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm" |
| 39 | + > |
| 40 | + <option value="">Select a role...</option> |
| 41 | + {roles.map((role) => ( |
| 42 | + <option key={role.id} value={role.id}> |
| 43 | + {role.name} |
| 44 | + {role.color !== 0 && ( |
| 45 | + <span |
| 46 | + style={{ |
| 47 | + color: `#${role.color.toString(16).padStart(6, "0")}`, |
| 48 | + }} |
| 49 | + > |
| 50 | + {" "} |
| 51 | + ● |
| 52 | + </span> |
| 53 | + )} |
| 54 | + </option> |
| 55 | + ))} |
| 56 | + </select> |
| 57 | + </div> |
| 58 | + <p className="mt-2 text-sm text-gray-500"> |
| 59 | + The role that grants moderator permissions to users. |
| 60 | + </p> |
| 61 | + </div> |
| 62 | + |
| 63 | + <div> |
| 64 | + <label |
| 65 | + htmlFor="mod_log_channel" |
| 66 | + className="block text-sm font-medium text-gray-700" |
| 67 | + > |
| 68 | + Mod Log Channel <span className="text-red-500">*</span> |
| 69 | + </label> |
| 70 | + <div className="mt-1"> |
| 71 | + <select |
| 72 | + id="mod_log_channel" |
| 73 | + name="mod_log_channel" |
| 74 | + required |
| 75 | + defaultValue={defaultValues?.modLogChannel || ""} |
| 76 | + className="block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 text-black shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm" |
| 77 | + > |
| 78 | + <option value="">Select a channel...</option> |
| 79 | + {channels.map((item) => { |
| 80 | + if (item.type === "channel") { |
| 81 | + return ( |
| 82 | + <option key={item.data.id} value={item.data.id}> |
| 83 | + #{item.data.name} |
| 84 | + </option> |
| 85 | + ); |
| 86 | + } else if ( |
| 87 | + item.type === "category" && |
| 88 | + item.children && |
| 89 | + item.children.length > 0 |
| 90 | + ) { |
| 91 | + return ( |
| 92 | + <optgroup |
| 93 | + key={item.data.id} |
| 94 | + label={item.data.name.toUpperCase()} |
| 95 | + > |
| 96 | + {item.children.map((channel) => ( |
| 97 | + <option key={channel.id} value={channel.id}> |
| 98 | + #{channel.name} |
| 99 | + </option> |
| 100 | + ))} |
| 101 | + </optgroup> |
| 102 | + ); |
| 103 | + } |
| 104 | + return null; |
| 105 | + })} |
| 106 | + </select> |
| 107 | + </div> |
| 108 | + <p className="mt-2 text-sm text-gray-500"> |
| 109 | + The channel where moderation reports will be sent. |
| 110 | + </p> |
| 111 | + </div> |
| 112 | + |
| 113 | + <div> |
| 114 | + <label |
| 115 | + htmlFor="restricted_role" |
| 116 | + className="block text-sm font-medium text-gray-700" |
| 117 | + > |
| 118 | + Restricted Role (Optional) |
| 119 | + </label> |
| 120 | + <div className="mt-1"> |
| 121 | + <select |
| 122 | + id="restricted_role" |
| 123 | + name="restricted_role" |
| 124 | + defaultValue={defaultValues?.restrictedRole || ""} |
| 125 | + className="block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 text-black shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm" |
| 126 | + > |
| 127 | + <option value="">Select a role...</option> |
| 128 | + {roles.map((role) => ( |
| 129 | + <option key={role.id} value={role.id}> |
| 130 | + {role.name} |
| 131 | + {role.color !== 0 && ( |
| 132 | + <span |
| 133 | + style={{ |
| 134 | + color: `#${role.color.toString(16).padStart(6, "0")}`, |
| 135 | + }} |
| 136 | + > |
| 137 | + {" "} |
| 138 | + ● |
| 139 | + </span> |
| 140 | + )} |
| 141 | + </option> |
| 142 | + ))} |
| 143 | + </select> |
| 144 | + </div> |
| 145 | + <p className="mt-2 text-sm text-gray-500"> |
| 146 | + A role that prevents members from accessing some channels during |
| 147 | + timeouts. |
| 148 | + </p> |
| 149 | + </div> |
| 150 | + |
| 151 | + {(roles.length === 0 || channels.length === 0) && ( |
| 152 | + <div className="rounded-md border border-yellow-200 bg-yellow-50 p-4"> |
| 153 | + <div className="flex"> |
| 154 | + <div className="ml-3"> |
| 155 | + <h3 className="text-sm font-medium text-yellow-800"> |
| 156 | + Unable to load server data |
| 157 | + </h3> |
| 158 | + <div className="mt-2 text-sm text-yellow-700"> |
| 159 | + <p> |
| 160 | + We couldn't fetch your server's roles and channels. Make sure |
| 161 | + Euno has proper permissions in your server. |
| 162 | + </p> |
| 163 | + </div> |
| 164 | + </div> |
| 165 | + </div> |
| 166 | + </div> |
| 167 | + )} |
| 168 | + |
| 169 | + <div> |
| 170 | + <button |
| 171 | + type="submit" |
| 172 | + className="flex w-full justify-center rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2" |
| 173 | + > |
| 174 | + {buttonText} |
| 175 | + </button> |
| 176 | + </div> |
| 177 | + </Form> |
| 178 | + ); |
| 179 | +} |
0 commit comments