All files / components PreferencesFields.tsx

100% Statements 158/158
100% Branches 19/19
100% Functions 11/11
100% Lines 158/158

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 1591x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 213x 213x 3x 3x 1x 2x 3x 213x 213x 213x 213x 213x 213x 213x 639x 639x 639x 639x 639x 639x 639x 639x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 1278x 1278x 1278x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 852x 852x 852x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 426x 426x 426x 426x 426x 426x 426x 426x 426x 426x 426x 426x 426x 3408x 3408x 3408x 426x 426x 426x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x 213x  
import {
  ARRANGEMENT_OPTIONS,
  OFFICE_DAY_CHOICES,
  PERIOD_OPTIONS,
  SENIORITY_OPTIONS,
  type PreferencesForm,
} from "../../shared/preferencesForm";
import type { PreferenceArrangement, PreferencePeriod } from "../../shared/types/profile";
 
const FIELD =
  "rounded-lg border border-gray-200 bg-white px-2.5 py-1.5 text-sm text-gray-700 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-200";
const LABEL = "block text-sm font-medium text-gray-700 dark:text-gray-200";
 
interface Props {
  form: PreferencesForm;
  onChange: (next: PreferencesForm) => void;
  disabled?: boolean;
}
 
/** The structured preference fields of the profile editor (FR-015). */
export function PreferencesFields({ form, onChange, disabled }: Props) {
  const set = (patch: Partial<PreferencesForm>) => onChange({ ...form, ...patch });
  const toggleArrangement = (value: PreferenceArrangement) =>
    set({
      arrangements: form.arrangements.includes(value)
        ? form.arrangements.filter((a) => a !== value)
        : [...form.arrangements, value],
    });
 
  return (
    <div className="mt-2 grid gap-4 sm:grid-cols-2">
      <fieldset className="sm:col-span-2" disabled={disabled}>
        <legend className={LABEL}>Work arrangement</legend>
        <div className="mt-1 flex gap-4">
          {ARRANGEMENT_OPTIONS.map((o) => (
            <label key={o.value} className="flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-200">
              <input
                type="checkbox"
                checked={form.arrangements.includes(o.value)}
                onChange={() => toggleArrangement(o.value)}
              />
              {o.label}
            </label>
          ))}
        </div>
      </fieldset>
 
      <div>
        <label htmlFor="pref-office-days" className={LABEL}>
          Maximum office days
        </label>
        <select
          id="pref-office-days"
          className={`mt-1 ${FIELD}`}
          value={form.maxOfficeDays}
          disabled={disabled}
          onChange={(e) => set({ maxOfficeDays: e.target.value })}
        >
          <option value="">No limit</option>
          {OFFICE_DAY_CHOICES.map((d) => (
            <option key={d} value={d}>
              {d}
            </option>
          ))}
        </select>
      </div>
 
      <div className="flex flex-wrap items-end gap-2">
        <div>
          <label htmlFor="pref-salary" className={LABEL}>
            Minimum salary
          </label>
          <input
            id="pref-salary"
            inputMode="numeric"
            className={`mt-1 w-28 ${FIELD}`}
            value={form.salaryAmount}
            disabled={disabled}
            onChange={(e) => set({ salaryAmount: e.target.value })}
          />
        </div>
        <input
          aria-label="Salary currency"
          maxLength={3}
          className={`w-16 uppercase ${FIELD}`}
          value={form.salaryCurrency}
          disabled={disabled}
          onChange={(e) => set({ salaryCurrency: e.target.value })}
        />
        <select
          aria-label="Salary period"
          className={FIELD}
          value={form.salaryPeriod}
          disabled={disabled}
          onChange={(e) => set({ salaryPeriod: e.target.value as PreferencePeriod })}
        >
          {PERIOD_OPTIONS.map((p) => (
            <option key={p.value} value={p.value}>
              {p.label}
            </option>
          ))}
        </select>
      </div>
 
      {(
        [
          ["Minimum seniority", "seniorityMin", "No minimum"],
          ["Maximum seniority", "seniorityMax", "No maximum"],
        ] as const
      ).map(([label, key, none]) => (
        <div key={key}>
          <label htmlFor={`pref-${key}`} className={LABEL}>
            {label}
          </label>
          <select
            id={`pref-${key}`}
            className={`mt-1 ${FIELD}`}
            value={form[key]}
            disabled={disabled}
            onChange={(e) => set({ [key]: e.target.value })}
          >
            <option value="">{none}</option>
            {SENIORITY_OPTIONS.map((o) => (
              <option key={o.value} value={o.value}>
                {o.label}
              </option>
            ))}
          </select>
        </div>
      ))}
 
      <div className="sm:col-span-2">
        <label htmlFor="pref-locations" className={LABEL}>
          Locations or timezones (one per line)
        </label>
        <textarea
          id="pref-locations"
          rows={2}
          className={`mt-1 w-full resize-none ${FIELD}`}
          placeholder="EU timezones only"
          value={form.locations}
          disabled={disabled}
          onChange={(e) => set({ locations: e.target.value })}
        />
      </div>
 
      <label className="flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-200 sm:col-span-2">
        <input
          type="checkbox"
          checked={form.needsSponsorship}
          disabled={disabled}
          onChange={(e) => set({ needsSponsorship: e.target.checked })}
        />
        I need visa sponsorship
      </label>
    </div>
  );
}